Repeat the same macro twice?

Lincoln Six Echo

Board Regular
Joined
Aug 8, 2008
Messages
92
Hi,

I have the following code to show the last date on which data was updated in column I.

The first section works fine. When I update column I, today's date shows up in column 17 (Q) on that row. However, regardless of what I change, I can't seem to get the second section to work. Basically, I want to add the current date to column 18 (R) for the row that was edited whenever a cell between A and P is updated.

What do I need to change in the 2nd statement to make Excel recognize both?

Thanks for your help.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = 0
If Not Intersect(Target, Range("I:I")) Is Nothing Then
If Target.Rows.Count > 17 Then
If Target.Column = 17 Then Cells(Target.Row, 17).Resize(UBound(Target.Value)).Value = Date
Cells(Target.Row, 17).Resize(UBound(Target.Value)).Value = Date
Else
If Target.Column = 17 Then Cells(Target.Row, 17).Value = Date
Cells(Target.Row, 17).Value = Date
End If
End If
Application.EnableEvents = 1
End Sub


Private Sub Worksheet_Change2(ByVal Target As Range)
Application.EnableEvents = 0
If Not Intersect(Target, Range("A:P")) Is Nothing Then
If Target.Rows.Count > 18 Then
If Target.Column = 18 Then Cells(Target.Row, 18).Resize(UBound(Target.Value)).Value = Date
Cells(Target.Row, 18).Resize(UBound(Target.Value)).Value = Date
Else
If Target.Column = 18 Then Cells(Target.Row, 18).Value = Date
Cells(Target.Row, 18).Value = Date
End If
End If
Application.EnableEvents = 1
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
"Private Sub Worksheet_Change2(ByVal Target As Range)"

Hi there,

Nice try, but that won't work. See, the worksheet change and other events, are supplied by Excel. That is to say, they are "pre-written" if you will, events that trap some action, in this case, changing a cell or cells. Thus, Excel simply isn't going to do anything with the second procedure.

You'll want to combine your new code into you existing, melding tests to cover possibilities and what code should be run.

Mark
 
Upvote 0
Does combining all of your if statements answers the question?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = 0
If Not Intersect(Target, Range("I:I")) Is Nothing Then
If Target.Rows.Count > 17 Then
If Target.Column = 17 Then Cells(Target.Row, 17).Resize(UBound(Target.Value)).Value = Date
Cells(Target.Row, 17).Resize(UBound(Target.Value)).Value = Date
Else
If Target.Column = 17 Then Cells(Target.Row, 17).Value = Date
Cells(Target.Row, 17).Value = Date
End If
End If

If Not Intersect(Target, Range("A:P")) Is Nothing Then
If Target.Rows.Count > 18 Then
If Target.Column = 18 Then Cells(Target.Row, 18).Resize(UBound(Target.Value)).Value = Date
Cells(Target.Row, 18).Resize(UBound(Target.Value)).Value = Date
Else
If Target.Column = 18 Then Cells(Target.Row, 18).Value = Date
Cells(Target.Row, 18).Value = Date
End If
End If

Application.EnableEvents = 1

End Sub

-e.rgabrieldoronila
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,487
Members
452,917
Latest member
MrsMSalt

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