Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default How to multi-select worksheets?

Hi, All

I have multiple worksheets, when i write below VBA code, it's ok:

Sheets(Array("Sheet1", "Sheet2",....)).Select

But when i assign it to a variable:

Sub Macro1()
Dim str As String
str = "Sheet1" & Chr(44) & "Sheet2"
Sheets(Array(str)).Select
End Sub

It seems doesn't work, what i can do?


Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default How to multi-select worksheets?

Hi OKLover,

Try:

'=============
Public Sub Macro1()
Dim arr As Variant

arr = Array("Sheet1", "Sheet2")
Sheets(arr).Select

End Sub
'<<=============

---
Regards,
Norman


"OKLover" wrote in message
...
Hi, All

I have multiple worksheets, when i write below VBA code, it's ok:

Sheets(Array("Sheet1", "Sheet2",....)).Select

But when i assign it to a variable:

Sub Macro1()
Dim str As String
str = "Sheet1" & Chr(44) & "Sheet2"
Sheets(Array(str)).Select
End Sub

It seems doesn't work, what i can do?


Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to multi-select worksheets?

Try this

Dim str As Variant
str = Array("Sheet1", "Sheet2")
Sheets(str).Select


--

HTH

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


"OKLover" wrote in message
...
Hi, All

I have multiple worksheets, when i write below VBA code, it's ok:

Sheets(Array("Sheet1", "Sheet2",....)).Select

But when i assign it to a variable:

Sub Macro1()
Dim str As String
str = "Sheet1" & Chr(44) & "Sheet2"
Sheets(Array(str)).Select
End Sub

It seems doesn't work, what i can do?


Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default How to multi-select worksheets?

Thanks, Norman and Bob

But what i need is loop current workbook to filter and select some worksheets.

ex:

I have five worksheets: sheet1, sheet2, sheet_aa, sheet_ba, sheet_ca

For Each tSheet In thisworkbook.worksheets
If Instr(tSheet.Name, "a") Then
'** Select all of the worksheet which name include the 'a'
End If
Next

What i can do?



"OKLover" wrote:

Hi, All

I have multiple worksheets, when i write below VBA code, it's ok:

Sheets(Array("Sheet1", "Sheet2",....)).Select

But when i assign it to a variable:

Sub Macro1()
Dim str As String
str = "Sheet1" & Chr(44) & "Sheet2"
Sheets(Array(str)).Select
End Sub

It seems doesn't work, what i can do?


Thanks

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default How to multi-select worksheets?

Hi OKLover,

So select all the sheets whose names include the letter 'a2, try:

'============
Sub ATester01()
Dim Sh As Worksheet

For Each Sh In ActiveWorkbook.Worksheets
If InStr(1, Sh.Name, "a") Then
Sh.Select False
End If
Next Sh
End Sub
'<<============


---
Regards,
Norman


"OKLover" wrote in message
...
Thanks, Norman and Bob

But what i need is loop current workbook to filter and select some
worksheets.

ex:

I have five worksheets: sheet1, sheet2, sheet_aa, sheet_ba, sheet_ca

For Each tSheet In thisworkbook.worksheets
If Instr(tSheet.Name, "a") Then
'** Select all of the worksheet which name include the 'a'
End If
Next

What i can do?



"OKLover" wrote:

Hi, All

I have multiple worksheets, when i write below VBA code, it's ok:

Sheets(Array("Sheet1", "Sheet2",....)).Select

But when i assign it to a variable:

Sub Macro1()
Dim str As String
str = "Sheet1" & Chr(44) & "Sheet2"
Sheets(Array(str)).Select
End Sub

It seems doesn't work, what i can do?


Thanks





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default How to multi-select worksheets?

Hi OkLover,

So select all the sheets whose names include the letter 'a2, try:


includes a typo. It should, of course, read:

So select all the sheets whose names include the letter 'a', try:

---
Regards,
Norman


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to multi-select worksheets?

Dim arySheets As Variant
Dim sh As Worksheet
Dim i As Long
ReDim arySheets(0 To 0)
For Each sh In ActiveWorkbook.Worksheets
If LCase(sh.Name) Like "*a*" Then
ReDim arySheets(0 To i)
arySheets(i) = sh.Name
i = i + 1
End If
Next sh
Sheets(arySheets).Select


--

HTH

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


"OKLover" wrote in message
...
Thanks, Norman and Bob

But what i need is loop current workbook to filter and select some

worksheets.

ex:

I have five worksheets: sheet1, sheet2, sheet_aa, sheet_ba, sheet_ca

For Each tSheet In thisworkbook.worksheets
If Instr(tSheet.Name, "a") Then
'** Select all of the worksheet which name include the 'a'
End If
Next

What i can do?



"OKLover" wrote:

Hi, All

I have multiple worksheets, when i write below VBA code, it's ok:

Sheets(Array("Sheet1", "Sheet2",....)).Select

But when i assign it to a variable:

Sub Macro1()
Dim str As String
str = "Sheet1" & Chr(44) & "Sheet2"
Sheets(Array(str)).Select
End Sub

It seems doesn't work, what i can do?


Thanks



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default How to multi-select worksheets?

Hi Norman,

Just a little tweak to your code so that the activesheet is not included
in the grouping unless it also includes 'a' in tab name.

Sub ATester01()
Dim Sh As Worksheet
Dim blnReplace As Boolean

blnReplace = True
For Each Sh In ActiveWorkbook.Worksheets
If InStr(1, Sh.Name, "a") Then
Sh.Select blnReplace
blnReplace = False
End If
Next Sh
End Sub

Cheers
Andy

Norman Jones wrote:
Hi OkLover,


So select all the sheets whose names include the letter 'a2, try:



includes a typo. It should, of course, read:

So select all the sheets whose names include the letter 'a', try:

---
Regards,
Norman



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default How to multi-select worksheets?

Hi Andy,

Good point!

Thank you.

---
Regards,
Norman



"Andy Pope" wrote in message
...
Hi Norman,

Just a little tweak to your code so that the activesheet is not included
in the grouping unless it also includes 'a' in tab name.

Sub ATester01()
Dim Sh As Worksheet
Dim blnReplace As Boolean

blnReplace = True
For Each Sh In ActiveWorkbook.Worksheets
If InStr(1, Sh.Name, "a") Then
Sh.Select blnReplace
blnReplace = False
End If
Next Sh
End Sub

Cheers
Andy

Norman Jones wrote:
Hi OkLover,


So select all the sheets whose names include the letter 'a2, try:



includes a typo. It should, of course, read:

So select all the sheets whose names include the letter 'a', try:

---
Regards,
Norman



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info



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
Is it possible to select a multi value from a drop down box Carrie Excel Discussion (Misc queries) 12 June 10th 09 08:10 PM
Multi Select Cells David Excel Programming 2 February 15th 05 06:35 PM
multi select listbox Paul Mueller Excel Programming 2 June 10th 04 09:08 PM
Extract values from a multi-select multi-column list-box Peter[_20_] Excel Programming 5 September 28th 03 04:04 PM
Multi Select List Box jacqui Excel Programming 0 July 22nd 03 12:12 PM


All times are GMT +1. The time now is 10:49 AM.

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

About Us

"It's about Microsoft Excel"