Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
jC! jC! is offline
external usenet poster
 
Posts: 10
Default count Worksheet using Wildcard

hi all,

find following my Sub:

Sub countTestCases()
Dim Sht As Object
Dim nr As Integer
nr = 0
For Each Sht In ActiveWorkbook.Sheets
If Sht.name = "TestCases*" Then nr = nr + 1
Next
MsgBox nr
End Sub

this is simply to count how many Worksheets starting with the name
"TestCases" are in the current Workbook. for example there might be
"TestCases0",
"TestCases5" and
"TestCases14",
if i execute above routine all i end up with is 0 for nr (but my goal
is it to display 3).

i assumed that by using the wildcard character "*" at the end of the
name "TestCases", this would count for it - either i am wrong with my
assumption or i implemeted incorrectly.

if any of you could point out what i am doing wrong or maybe there is
a more elegant way of writing above code, this would be mostly
appreciated.

cheers....


....jurgenC!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default count Worksheet using Wildcard

Hi Jurgen,

How about this

Sub countTestCases()
Dim Sht As Object
Dim nr As Integer
nr = 0
For Each Sht In ActiveWorkbook.Sheets
If InStr(Sht.Name, "TestCases") 0 Then nr = nr + 1
Next
MsgBox nr
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"jC!" wrote in message
om...
hi all,

find following my Sub:

Sub countTestCases()
Dim Sht As Object
Dim nr As Integer
nr = 0
For Each Sht In ActiveWorkbook.Sheets
If Sht.name = "TestCases*" Then nr = nr + 1
Next
MsgBox nr
End Sub

this is simply to count how many Worksheets starting with the name
"TestCases" are in the current Workbook. for example there might be
"TestCases0",
"TestCases5" and
"TestCases14",
if i execute above routine all i end up with is 0 for nr (but my goal
is it to display 3).

i assumed that by using the wildcard character "*" at the end of the
name "TestCases", this would count for it - either i am wrong with my
assumption or i implemeted incorrectly.

if any of you could point out what i am doing wrong or maybe there is
a more elegant way of writing above code, this would be mostly
appreciated.

cheers....


...jurgenC!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default count Worksheet using Wildcard

hi Bob and Heiko,

thank you very much for your comments, both are very elegant.

cheers....


....jurgenC!

remove "somewhere" from eMail when replying direct

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default count Worksheet using Wildcard

Same as you have , but try "like" instead of = for your
If statement.

Merry Christmas

Sub countTestCases()
Dim Sht As Object
Dim nr As Integer
nr = 0
For Each Sht In ActiveWorkbook.Sheets
If Sht.name like "TestCases*" Then nr = nr + 1
Next
MsgBox nr
End Sub
-----Original Message-----
hi all,

find following my Sub:

Sub countTestCases()
Dim Sht As Object
Dim nr As Integer
nr = 0
For Each Sht In ActiveWorkbook.Sheets
If Sht.name = "TestCases*" Then nr = nr + 1
Next
MsgBox nr
End Sub

this is simply to count how many Worksheets starting

with the name
"TestCases" are in the current Workbook. for example

there might be
"TestCases0",
"TestCases5" and
"TestCases14",
if i execute above routine all i end up with is 0 for nr

(but my goal
is it to display 3).

i assumed that by using the wildcard character "*" at

the end of the
name "TestCases", this would count for it - either i am

wrong with my
assumption or i implemeted incorrectly.

if any of you could point out what i am doing wrong or

maybe there is
a more elegant way of writing above code, this would be

mostly
appreciated.

cheers....


....jurgenC!
.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default count Worksheet using Wildcard

hi David,

merry xMas to you too - thanks for your solution, mostly appreciated.

cheers...

...jurgenC!

remove "somewhere" from eMail when replying direct

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
How do I count two conditions using a wildcard? NoNickName Excel Worksheet Functions 2 August 29th 07 06:26 PM
COUNT or COUNTIF using wildcard text? WiFiMike2006 Excel Worksheet Functions 11 January 12th 07 11:12 PM
How do I count wildcard text meeting certain criteria in EXCEL? cybermaksim Excel Worksheet Functions 1 February 17th 06 03:03 AM
Wildcard Usage: I absolutely need this to count?/sum? two or more criteri Inexcelhell Excel Discussion (Misc queries) 2 October 12th 05 03:11 PM
VBA: Select Excel's Worksheet using wildcard maxifire Excel Programming 5 December 15th 03 04:21 PM


All times are GMT +1. The time now is 05:39 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"