PDA

View Full Version : find if cell value changed



itsmaheshp
03-25-2009, 07:12 AM
Hi,
I am having an Excel where the users need to fill in all the details in a row from column 4 to 8. so the values on column 5 depends on column 4 and value on column 6 depends on column 5 and henceforth..

I need to detect if later the user changed the value in column 4 then I need to clear all the values on columns 5,6,7,8 for that row.

Please advice how this is possible.

Thanks,
Mahesh

nst1107
03-25-2009, 08:31 AM
I think this will do what you want:Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Columns(4)) Is Nothing Then Exit Sub
Target.Offset(, 1).Resize(, 4).ClearContents
End Sub

mdmackillop
03-25-2009, 10:22 AM
'Save changed rows
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 4 Then
Sheets(2).Cells(Rows.Count, 1).End(xlUp).Offset(1) = Target.Row
End If
End Sub

'Remove changes
Sub Reset()
On Error GoTo Exits
Application.EnableEvents = False
With Sheets(2)
Dim cel As Range
For Each cel In .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
Sheets(1).Cells(cel, 5).Resize(, 4).ClearContents
cel.ClearContents
Next
End With
Exits:
Application.EnableEvents = True
End Sub

itsmaheshp
03-26-2009, 12:16 PM
thanks for the code...
then how the Reset() function is called?

mdmackillop
03-26-2009, 02:26 PM
Put a button on the sheet next to where the data is written and assign it to the macro. When you see recorded changes and wish to clear it, then click the button.