ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Recognising which is the active sheet (https://www.excelbanter.com/excel-programming/360198-recognising-active-sheet.html)

Blondegirl[_4_]

Recognising which is the active sheet
 

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.


--
Blondegirl
------------------------------------------------------------------------
Blondegirl's Profile: http://www.excelforum.com/member.php...o&userid=29615
View this thread: http://www.excelforum.com/showthread...hreadid=537687


Ardus Petus

Recognising which is the active sheet
 
If Activesheet.Name = "Sheet2" or Activesheet.Name = "Sheet3" then

HTH
--
AP

"Blondegirl" a
écrit dans le message de
...

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.


--
Blondegirl
------------------------------------------------------------------------
Blondegirl's Profile:

http://www.excelforum.com/member.php...o&userid=29615
View this thread: http://www.excelforum.com/showthread...hreadid=537687




Bob Phillips[_6_]

Recognising which is the active sheet
 
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" wrote in message
...
If Activesheet.Name = "Sheet2" or Activesheet.Name = "Sheet3" then

HTH
--
AP

"Blondegirl" a
écrit dans le message de
...

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.


--
Blondegirl
------------------------------------------------------------------------
Blondegirl's Profile:

http://www.excelforum.com/member.php...o&userid=29615
View this thread:

http://www.excelforum.com/showthread...hreadid=537687






Tom Ogilvy

Recognising which is the active sheet
 
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" wrote:

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" wrote in message
...
If Activesheet.Name = "Sheet2" or Activesheet.Name = "Sheet3" then

HTH
--
AP

"Blondegirl" a
écrit dans le message de
...

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.


--
Blondegirl
------------------------------------------------------------------------
Blondegirl's Profile:

http://www.excelforum.com/member.php...o&userid=29615
View this thread:

http://www.excelforum.com/showthread...hreadid=537687








All times are GMT +1. The time now is 10:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com