Niki_Ivanov
New Member
- Joined
- Aug 11, 2017
- Messages
- 6
Hi,
I want to create a VBA Macro to show me when there is a change in any cell in a certain range.
I found the below and amended to suit my sheet , but it does the trick , but it only works for 1 column not a range of columns .. as you can see the offset is -3 .. and it shows date and time 3 column prior the column in which a cell was amended .. and if i put a range of multiple columns i want it always to show the date and time of change in 1 certain cell rather than -3 columns of the cell amended . I was thinking of creating the same macro for each column and offset -3 , -4 , -5 respectively but can't combine for some reason. ANy help will be appreciated . I hope you explained it right .. thanks !
Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20140722
Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("D:D"), Target)
xOffsetColumn = -3
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Now
Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy, hh:mm:ss"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
End Sub
I want to create a VBA Macro to show me when there is a change in any cell in a certain range.
I found the below and amended to suit my sheet , but it does the trick , but it only works for 1 column not a range of columns .. as you can see the offset is -3 .. and it shows date and time 3 column prior the column in which a cell was amended .. and if i put a range of multiple columns i want it always to show the date and time of change in 1 certain cell rather than -3 columns of the cell amended . I was thinking of creating the same macro for each column and offset -3 , -4 , -5 respectively but can't combine for some reason. ANy help will be appreciated . I hope you explained it right .. thanks !
Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20140722
Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("D:D"), Target)
xOffsetColumn = -3
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Now
Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy, hh:mm:ss"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
End Sub