Recognising which is the active sheet

  • Thread starter Thread starter Blondegirl
  • Start date Start date
B

Blondegirl

Hello,

I'm sure this is a really simple one to ask but I'm a VBA newbie! I
need my code to recognise which is the current active sheet but I don't
know the correct syntax for it within an IF statement. Here is my draft
coding:

Private Sub CommandButton1_Click()

If ActiveSheet = "Sheet 2" OR "Sheet 3" OR "Sheet 6" Then
frmAddrecord1.Show
Else
frmAddrecord2.Show
End If
End Sub

Also, as an alternative, please could you also help on the correct
coding it would be via the Case select method.
Thank you.
 
For interest, another way

Private Sub CommandButton1_Click()

If Not IsError(Application.Match(ActiveSheet.Name, Array("Sheet2", "Sheet3",
"Sheet6"))) Then
frmAddrecord1.Show
Else
frmAddrecord2.Show
End If
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

Ardus Petus said:
If Activesheet.Name = "Sheet2" or Activesheet.Name = "Sheet3" then

HTH
 
Select Case Activesheet.Name
Case "Sheet2"
msgbox "Activesheet is Sheet2"
Case "Sheet3"
msgbox "Activesheet is Sheet3"
Case Else
msgbox "Activesheet is neither Sheet2 or Sheet3"
End Select

--
Regards,
Tom Ogilvy

Bob Phillips said:
For interest, another way

Private Sub CommandButton1_Click()

If Not IsError(Application.Match(ActiveSheet.Name, Array("Sheet2", "Sheet3",
"Sheet6"))) Then
frmAddrecord1.Show
Else
frmAddrecord2.Show
End If
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 

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

Back
Top