Determining the Active Worksheet

O

ordnance1

My problem here is of course in line 1. I need the code to run based on what
worksheet is active. There will be a series of these if statements (if May
is active I will select May - September and so on). So is there any way to
write the first line to determine the active worksheet?


Sub Macro2()

If Worksheets("April").Active = True Then

Sheets(Array("April", "May", "June", "July", "August",
"September")).Select

End If

End Sub
 
W

Wouter HM

Hi ordnance1,

For your first line you can use:

If ActiveSheet.Name = "April" Then

HTH,

Wouter
 
D

Don Guillett

if activeworksheet.name="April" then
do this
else
do that
end if

Or instead of selecting, just do what you need to do for sheet2(Jan) to
sheet13(Dec)
Sub dorestofsheets()
'MsgBox ActiveSheet.Index
For i = ActiveSheet.Index To 13
Sheets(i).Range("a1") = 1
Next i
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

Top