Selecting sheets

D

Dr.Schwartz

How can make my code add a sheet to a selection?

Something like:

Dim WSName As Worksheet
For Each WSName In Worksheets
If Left(WSName.Name, 3) = "Pre" Then
'the code for adding the sheet to the selection
End If
Next

Thanks
The Doctor
 
F

FSt1

hi,

Sheets.add would add a sheet to the workbook but i'm not sure if this is
what you want. could you clairify.


FSt1
 
K

KL

Maybe something like this:

Sub test()
Dim temp As Variant, WSName As Worksheet
ReDim temp(0)
For Each WSName In Worksheets
If Left(WSName.Name, 3) = "Pre" Then
temp(UBound(temp)) = WSName.Name
ReDim Preserve temp(UBound(temp) + 1)
End If
Next WSName
ReDim Preserve temp(UBound(temp) - 1)
Sheets(temp).Select
End Sub

Regards,
KL
 
D

Dr.Schwartz

I simply want to select all sheets where the first three letters of the sheet
name is "Pre".

Manually I just left mouse click on the sheet tabs I want to select while
pressing Ctrl.
 
B

Bob Phillips

Dim sSheets As String
Dim cSheets As Long
Dim sh As Worksheet

ReDim arySheets(1 To 1)
For Each sh In ActiveWorkbook.Worksheets
If Left(sh.Name, 3) = "Pre" Then
sSheets = sSheets & sh.Name & ","
End If
Next sh

sSheets = Left(sSheets, Len(sSheets) - 1)
Worksheets(Split(sSheets, ",")).Select


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Top