Private Sub - range for every sencond column

Eskild

New Member
Joined
May 6, 2019
Messages
5
Hej guys.
I have this little problem.
I would like to make it the same for every second row, but i cant figure out how to set the range correctly.
I want to type "x" in a random cell i column D or F, and the timesample will emerge one the cell to the right.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim B As Range: Set B = Range("B:B")
Dim v As String
If Intersect(Target, B) Is Nothing Then Exit Sub
Application.EnableEvents = False
v = Target.Value
If v = "x" Then Target.Offset(0, 1) = Now()
If v = "1" Then Target.Offset(0, 1) = Now()
Application.EnableEvents = True
End Sub

Hope you can helpo!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim B As Range: Set B = Range("[COLOR=#ff0000]D:D,F:F[/COLOR]")
    Dim v As String
    If Intersect(Target, B) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    v = Target.Value
    If v = "x" Then Target.Offset(0, 1) = Now()
    If v = "1" Then Target.Offset(0, 1) = Now()
    Application.EnableEvents = True
End Sub
 
Upvote 0
Welcome to the MrExcel Board.

Change this line:

Code:
[COLOR=#333333]If Intersect(Target, B) Is Nothing Then Exit Sub[/COLOR]


to

Code:
If Target.Column Mod 2 = 1 Then Exit Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top