Select Range instead of a whole column

Artfight

New Member
Joined
Aug 21, 2017
Messages
3
I am interested in using this great VBA that I borrowed from MrExcel but instead of selecting all of column "d" to trigger a time stamp I would like to use a selected range of cells...say range c3:f100.

Can someone help me adjust this VBA...THANKS

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 4 Then
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
If Len(Range("D" & Target.Row)) = 0 Then
Range("B" & Target.Row).ClearContents
Else
Range("B" & Target.Row).Value = Now()
End If
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End If

End Sub
 

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.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("C3:F100")) Is Nothing Then


etc etc
 
Upvote 0
This was so close to what I need. I appreciate the help. I used your suggestions and here are my results:

Time stamp is only triggered when I do an entry in the D column but I wish it to be triggered when an entry is done in any row or column in the range c3:f100. It does however work to not trigger the timestamp until I reach D3 or lower (d1 not timestamp, d2 no timestamp).

here is what I have now,

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Application.Intersect(Target, Range("C3:F100")) Is Nothing Then
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
If Len(Range("D" & Target.Row)) = 0 Then
Range("B" & Target.Row).ClearContents
Else
Range("B" & Target.Row).Value = Now()
End If
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End If

End Sub



Thank you,
Scott
 
Upvote 0
Hello Scott,

You have set the range to start at row 3 (C3:F100)... so typing anything in D1 or D2 would not trigger the macro. Try this update:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect(Target, Range("C3:F100")) Is Nothing Then
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
    If Len(Cells(Target.Row, Target.Column)) = 0 Then
        Range("B" & Target.Row).ClearContents
    Else
        Range("B" & Target.Row).Value = Now()
    End If
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
    End If
End Sub

Caleeco
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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