Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Check Worksheet Name and Select if Meets Criteria

Hi everyone, i have what i think is a very easy question. I'm trying
to select all the worksheets in my workbook that start with the
"Data". i wrote this vba code, and even though i put a watch on the
left formula and it shows "Data" in the watch window, it never selects
the sheet. Any help would be much appreciated!!!!

Sub SelectCockpit()
'
' Selects all tabs with cockpit in first 6 digits

Dim wksSheet As Worksheet

Sheets(1).Activate
For Each wksSheet In Worksheets
If Left(wksSheet.Name, 4) = "Data" Then
wksSheet.Select
End If
Next wksSheet
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 915
Default Check Worksheet Name and Select if Meets Criteria

ainbinder wrote:
Hi everyone, i have what i think is a very easy question. I'm trying
to select all the worksheets in my workbook that start with the
"Data". i wrote this vba code, and even though i put a watch on the
left formula and it shows "Data" in the watch window, it never selects
the sheet. Any help would be much appreciated!!!!

Sub SelectCockpit()
'
' Selects all tabs with cockpit in first 6 digits

Dim wksSheet As Worksheet

Sheets(1).Activate
For Each wksSheet In Worksheets
If Left(wksSheet.Name, 4) = "Data" Then
wksSheet.Select
End If
Next wksSheet



I learned something. It turns out selecting multiple worksheets is done
by passing an array to the Select method. Try this:

Sub SelectCockpit()
'
' Selects all tabs with cockpit in first 6 digits

Dim wksSheet As Worksheet
Dim SheetNames() As String
Dim i As Long

i = 1
Sheets(1).Activate
For Each wksSheet In Worksheets
If Left(wksSheet.Name, 4) = "Data" Then
ReDim Preserve SheetNames(1 To i)
SheetNames(i) = wksSheet.Name
i = i + 1
End If
Next wksSheet
Sheets(SheetNames).Select

End Sub
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
if cell in other worksheet meets criteria, then leave blank. JudyK Excel Discussion (Misc queries) 1 April 9th 10 05:35 PM
Sum of total from other worksheet with that meets one criteria Excel Sum function with IF Excel Worksheet Functions 10 May 25th 09 06:05 PM
Add up a value that meets 2 criteria Lee Excel Discussion (Misc queries) 6 November 18th 08 09:38 PM
Populate worksheet with data that meets date range criteria P0llyW0G Excel Worksheet Functions 3 September 28th 08 10:01 PM
Do Nothing If Meets Criteria kmwhitt Excel Discussion (Misc queries) 2 September 20th 06 05:49 PM


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