Help with Time Stamp Macro

Hjemmet

Board Regular
Joined
Jun 20, 2018
Messages
207
Hey I Need some Help with This Code
the code works fine for colum "L" but i need it work on severel Colom's

the Colom's i need is "L" and "U" and "AD" and "AM" and "AW"

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Columns("L"), Target.Parent.UsedRange) Is Nothing Then
        On Error GoTo Safe_Exit
        Application.EnableEvents = False
        Dim rng As Range
        For Each rng In Intersect(Target, Columns("L"), Target.Parent.UsedRange)
            If CBool(Len(rng.Value2)) And Not CBool(Len(rng.Offset(0, 1).Value2)) Then
                rng.Offset(0, 1) = Now
            ElseIf Not CBool(Len(rng.Value2)) And CBool(Len(rng.Offset(0, 1).Value2)) Then
                rng.Offset(0, 1) = vbNullString
            End If
        Next rng
    End If
Safe_Exit:
    Application.EnableEvents = True
End Sub

hope that are enough Info
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Would you please explain in words what your wanting this code to do.
I always have a hard time reading other peoples code and then trying to modify it to do all they want.
Thanks.
 
Upvote 0
Try this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, [B][COLOR=#0000cd]Range("L:L,U:U,AD:AD,AM:AM,AW:AW")[/COLOR][/B], Target.Parent.UsedRange) Is Nothing Then
        On Error GoTo Safe_Exit
        Application.EnableEvents = False
        Dim rng As Range
        For Each rng In Intersect(Target, [B][COLOR=#0000cd]Range("L:L,U:U,AD:AD,AM:AM,AW:AW")[/COLOR][/B], Target.Parent.UsedRange)
            If CBool(Len(rng.Value2)) And Not CBool(Len(rng.Offset(0, 1).Value2)) Then
                rng.Offset(0, 1) = Now
            ElseIf Not CBool(Len(rng.Value2)) And CBool(Len(rng.Offset(0, 1).Value2)) Then
                rng.Offset(0, 1) = vbNullString
            End If
        Next rng
    End If
Safe_Exit:
    Application.EnableEvents = True
End Sub
 
Upvote 0
Code Intersect used find Target have into Columns("L"). So now, Target only on Columns("L"). IF you want Columns: L, U, AD, AM, AW, so you need use other conditions.

Your conditions:
Code:
[COLOR=#333333]Private Sub Worksheet_Change(ByVal Target As Range)
[/COLOR][COLOR=#333333]    If Not Intersect(Target, Columns("L"), Target.Parent.UsedRange) Is Nothing Then

[/COLOR]..
End If
End Sub

The corresponding column {L, U, AD, AM, AW} is {12, 21, 30, 39, 49}:

Code:
[COLOR=#333333]Private Sub Worksheet_Change(ByVal Target As Range)
IF Target.Column = 12 or Target.Column = 21 or Target.Column = 30 or Target.Column = 39 or Target.Column = 49 Then
'...
End IF
End Sub

[/COLOR]

OR:

Code:
[COLOR=#333333]Private Sub Worksheet_Change(ByVal Target As Range)
IF [/COLOR]Instr(1, ",12,21,30,39,49,", "," & [COLOR=#333333]Target.Column & ","[/COLOR])[COLOR=#333333] Then
'...
End IF
End Sub

[/COLOR]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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