One more.
Option Explicit
Sub SelectCockpit()
Dim wksSheet As Worksheet
Dim iCtr As Long
Dim WksNames() As String
ReDim WksNames(1 To Worksheets.Count)
iCtr = 0
For Each wksSheet In Worksheets
If LCase(Left(wksSheet.Name, 4)) = LCase("Data") Then
If wksSheet.Visible = xlSheetVisible Then
iCtr = iCtr + 1
WksNames(iCtr) = wksSheet.Name
End If
End If
Next wksSheet
If iCtr = 0 Then
MsgBox "no sheet names qualify!"
Else
ReDim Preserve WksNames(1 To iCtr)
Worksheets(WksNames).Select
End If
End Sub
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
> End Sub
--
Dave Peterson
|