Excel excel 2003 macro to run on specific worksheets only

Joined
Jan 16, 2012
Messages
1
Reaction score
0
Hi,

I'm new to PCreview and new to vb coding, below is my macro. Basically my workbook has ten worksheets, however i just want the code below to run if they are on sheet1 to sheet4. Please be very descriptive in your response as I am fairly green when it comes to vb coding. thanks in advance.


if possible, i would like it to check to see if its on the correct worksheet before running this macro. thanks again


Sub Macro1()
'
'
'


If ActiveCell.Address Like "$C*" Then
If ActiveCell.Offset(-1, -2) = "" Then
ActiveCell.Offset(-1, -2).Value = Now()
ActiveCell.Offset(-1, -1).Value = Now()
ActiveCell.Offset(-1, -1).NumberFormat = "h:mm AM/PM"
End If
End If

If ActiveCell.Address Like "$D*" Then
If ActiveCell.Offset(0, -3) = "" Then
ActiveCell.Offset(0, -3).Value = Now()
ActiveCell.Offset(0, -2).Value = Now()
ActiveCell.Offset(0, -2).NumberFormat = "h:mm AM/PM"
End If
End If
End Sub
 
Back
Top