Newbie Needing Help - Macro will only work in one sheet.

ijhannah

New Member
Joined
Feb 25, 2019
Messages
3
Hello,

I'm not familiar at all with using VBA so please bear with me. I am trying to get the below code to work on all the sheets. It works on Sheet 1, but not the rest within the same workbook.

I've read another thread w/ similar question, but the codes are so different I don't even know where to begin. Please help!

All I'm trying to do is have Cell E automatically reflect the current date when an entry is made on Cell D and tabbed over. This must be activated on all 12 sheets in the same workbook.

Thanks in advance.


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'Updated by Hannah Yu 02/21/2019
Dim xRg As Range, xCell As Range
On Error Resume Next
If (Target.Count = 1) Then
If (Not Application.Intersect(Target, Me.Range("D:D")) Is Nothing) Then _
Target.Offset(0, 1) = Date
Application.EnableEvents = False
Set xRg = Application.Intersect(Target.Dependents, Me.Range("D:D"))
If (Not xRg Is Nothing) Then
For Each xCell In xRg
xCell.Offset(0, 1) = Date
Next
End If
Application.EnableEvents = True
End If
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Remove your macro and put the following code in the Thisworkbook events, this will make it work on all the sheets.
Only the following lines of code are required:

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If Target.Count = 1 Then
        If Not Application.Intersect(Target, Range("D:D")) Is Nothing Then
            Target.Offset(0, 1) = Date
        End If
    End If
End Sub
 
Upvote 0
Sorry - meant to indicate that I'm trying to have column E automatically reflect the current date when an entry is made in a cell in column D.
 
Upvote 0
Sorry - meant to indicate that I'm trying to have column E automatically reflect the current date when an entry is made in a cell in column D.

Is that not what the code DanteAmor posted does :confused:
 
Upvote 0
Sorry - meant to indicate that I'm trying to have column E automatically reflect the current date when an entry is made in a cell in column D.

To put the code in the events of thisworkbook, go to VBA, in VBAProject press doubleclick in ThisWorkbook, in the panel paste the code.
Go back to excel and on any sheet, in column D enter a data, in automatic in column E you will have the date.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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