IrishDave2137
New Member
- Joined
- Jun 24, 2021
- Messages
- 8
- Office Version
- 365
- Platform
- Windows
Hi,
Hoping this isn't a stupid question but here goes
When I run the following code I want a change in column A (Target range) to trigger changes in columns C & D.
When I add a value to column A, the Date will be inserted into column C and Username to column D.
When I clear the value from column A, C & D should also clear.
However I can only get one column to populate using the code below.
If I run the code as provided only column C will change its value.
If I comment out references to 'Target.Offset(0.2)' then column D will populate with a value.
If I change the order in the code I can get column D to populate but not column C.
So in essence it will only change the first target offset and not subsequent offsets.
Does anyone know why this is happening and how I can get both columns C & D to populate when A is changes? Thanks
Hoping this isn't a stupid question but here goes
When I run the following code I want a change in column A (Target range) to trigger changes in columns C & D.
When I add a value to column A, the Date will be inserted into column C and Username to column D.
When I clear the value from column A, C & D should also clear.
However I can only get one column to populate using the code below.
If I run the code as provided only column C will change its value.
If I comment out references to 'Target.Offset(0.2)' then column D will populate with a value.
If I change the order in the code I can get column D to populate but not column C.
So in essence it will only change the first target offset and not subsequent offsets.
Does anyone know why this is happening and how I can get both columns C & D to populate when A is changes? Thanks
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim WS As Worksheet
Dim UserNameStr As String
Set WS = Sheets("Scan Sheet")
UserNameStr = Application.UserName
WS.Unprotect Password:="########"
If Not Intersect(Target, Range("A:A")) Is Nothing Then
On Error Resume Next
If Target.Value = "" Then
Target.Offset(0, 2) = ""
Target.Offset(0, 3) = ""
Else
Target.Offset(0, 2).Value = Format(Now, "mm/dd/yyyy HH:mm:ss")
Target.Offset(0, 3).Value = UserNameStr
End If
End If
WS.Protect Password:="#######", AllowSorting:=True, AllowFiltering:=True
End Sub