Renaming a program

cordellion

New Member
Joined
Mar 1, 2014
Messages
6
Hi I am new here (this is my second post) so this is a pretty basic question.

I am using the same macro twice on a sheet. It is for calculating the time. However, the sheet will not let me use both unless I rename one. This will show how new I am at this but I am not sure how to rename the macro. Whenever I have tried it stops functioning.

Below you will find the two programs I would like to use. Can anyone tell me how I can rename the first so that it continues to work?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'when entering data in a cell in Col A
On Error GoTo enditall
Application.EnableEvents = False
If Target.Cells.Column = 1 Then
n = Target.Row
If Me.Range("A" & n).Value <> "" Then
Me.Range("B" & n).Value = Format(Now, "hh:mm:ss AM/PM")
End If
End If
enditall:
Application.EnableEvents = True
End Sub
---
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'when entering data in a cell in Col C
On Error GoTo enditall
Application.EnableEvents = False
If Target.Cells.Column = 3 Then
n = Target.Row
If Me.Range("C" & n).Value <> "" Then
Me.Range("D" & n).Value = Format(Now, "hh:mm:ss AM/PM")
End If
End If
enditall:
Application.EnableEvents = True
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Don't rename anything, combine the 2 sets of code.
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
 'when entering data in a cell in Col A
On Error GoTo enditall
 
    If Not Intersect(Target, Range("A:A, C:C")) Is Nothing Then

        Application.EnableEvents = False
        If Target.Value  <> "" Then
            Target.offset(,1).Value = Format(Now, "hh:mm:ss AM/PM")
        End If
     End If

enditall:
    Application.EnableEvents = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,216,122
Messages
6,128,967
Members
449,480
Latest member
yesitisasport

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