Excel excel 2003 macro to run on specific worksheets only

Jan 16, 2012
Reaction score

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


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question