Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Test worksheet name

Hallo,
I would need to test whether the active sheet has one of the name from
several possibilities.

I tried the simple code below, but it is ending with error.

Sub worksheet_name_test()

Dim wks As Worksheet
If Not wks.Name = "Revenue" Or wks.Name = "SF Revenue" Or wks.Name =
"Rbn" Then
MsgBox "Correct sheet was not chosen!", vbCritical
End If
End Sub


Thank you in advance for any suggestions.

Petr Duzbaba
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Test worksheet name

Hi Petr

Try this one

With ActiveSheet
If Not .Name = "Revenue" Or .Name = "SF Revenue" _
Or .Name = "Rbn" Then
MsgBox "Correct sheet was not chosen!", vbCritical
End If
End With


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Petr" wrote in message om...
Hallo,
I would need to test whether the active sheet has one of the name from
several possibilities.

I tried the simple code below, but it is ending with error.

Sub worksheet_name_test()

Dim wks As Worksheet
If Not wks.Name = "Revenue" Or wks.Name = "SF Revenue" Or wks.Name =
"Rbn" Then
MsgBox "Correct sheet was not chosen!", vbCritical
End If
End Sub


Thank you in advance for any suggestions.

Petr Duzbaba



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Test worksheet name

Petr,

on behalf of all Dutchmen: thanks for getting us into the
quarterfinals, I hope you'll regret it in the finals :-)




Dim wks As Worksheet
If Not wks.Name = "Revenue" Or wks.Name = "SF Revenue" Or wks.Name =


if you just want to test the activesheet, you dont need the wks variable
= use instead activesheet.name etc..

however you probably included the wks variable to keep your code short.
BUT you forgot to assign it a value (or in this case an object)

dim wks as worksheet
SET wks = activesheet
....your code

alternatively use a select case statement:

select case lcase$(activesheet.name)
case "revenue","sf revenue","rbn"
'ok
case else
msgbox "Please select a Revenue sheet!", vbCritical
end select





keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


(Petr) wrote:

Hallo,
I would need to test whether the active sheet has one of the name from
several possibilities.

I tried the simple code below, but it is ending with error.

Sub worksheet_name_test()

Dim wks As Worksheet
If Not wks.Name = "Revenue" Or wks.Name = "SF Revenue" Or wks.Name =
"Rbn" Then
MsgBox "Correct sheet was not chosen!", vbCritical
End If
End Sub


Thank you in advance for any suggestions.

Petr Duzbaba


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Test worksheet name

Hi keepITcool

on behalf of all Dutchmen: thanks for getting us into the
quarterfinals, I hope you'll regret it in the finals :-)


Here is a nice picture for the English fans<g
http://www.rondebruin.com/beckss.jpg

--
Regards Ron de Bruin
http://www.rondebruin.nl


"keepITcool" wrote in message ...
Petr,

on behalf of all Dutchmen: thanks for getting us into the
quarterfinals, I hope you'll regret it in the finals :-)




Dim wks As Worksheet
If Not wks.Name = "Revenue" Or wks.Name = "SF Revenue" Or wks.Name =


if you just want to test the activesheet, you dont need the wks variable
= use instead activesheet.name etc..

however you probably included the wks variable to keep your code short.
BUT you forgot to assign it a value (or in this case an object)

dim wks as worksheet
SET wks = activesheet
...your code

alternatively use a select case statement:

select case lcase$(activesheet.name)
case "revenue","sf revenue","rbn"
'ok
case else
msgbox "Please select a Revenue sheet!", vbCritical
end select





keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


(Petr) wrote:

Hallo,
I would need to test whether the active sheet has one of the name from
several possibilities.

I tried the simple code below, but it is ending with error.

Sub worksheet_name_test()

Dim wks As Worksheet
If Not wks.Name = "Revenue" Or wks.Name = "SF Revenue" Or wks.Name =
"Rbn" Then
MsgBox "Correct sheet was not chosen!", vbCritical
End If
End Sub


Thank you in advance for any suggestions.

Petr Duzbaba




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Test worksheet name

If Not wks.Name = "Revenue" Or wks.Name = "SF Revenue" Or wks.Name = "Rbn"
Then

If wks.Name < "Revenue" Or wks.Name < "SF Revenue" Or wks.Name < "Rbn"
Then
or try with AND
If wks.Name < "Revenue" and wks.Name < "SF Revenue" and wks.Name < "Rbn"
Then

--
Don Guillett
SalesAid Software

"Petr" wrote in message
om...
Hallo,
I would need to test whether the active sheet has one of the name from
several possibilities.

I tried the simple code below, but it is ending with error.

Sub worksheet_name_test()

Dim wks As Worksheet
If Not wks.Name = "Revenue" Or wks.Name = "SF Revenue" Or wks.Name =
"Rbn" Then
MsgBox "Correct sheet was not chosen!", vbCritical
End If
End Sub


Thank you in advance for any suggestions.

Petr Duzbaba



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Merged Cells in Worksheet, Test for [email protected] Excel Discussion (Misc queries) 2 September 28th 06 05:09 PM
If a worksheet name is = to test then a msgbox appears Vick Excel Discussion (Misc queries) 1 December 21st 05 11:17 PM
Test for Worksheet Paul Excel Programming 5 April 30th 04 10:29 PM
How can I test when any worksheet within a workbook is selected Peter McNaughton Excel Programming 2 January 29th 04 04:59 AM
Test to see if a worksheet exists thanks, Chip CT[_2_] Excel Programming 0 August 22nd 03 03:17 AM


All times are GMT +1. The time now is 05:58 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"