Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Selecting more than one sheet

Is there a way to write code to select sheets 1 to x number of sheets? I
have code that is counting the number of sheets in a workbook and subtracting
3 of those sheets already which is working.

What I want to do is select the sheets and copy to a new workbook.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Selecting more than one sheet

Steve,

Try something like the following:

Dim Sh1 As String
Dim Sh2 As String

Sh1 = "Sheet1"
Sh2 = "Sheet3"
Sheets(Array(Sh1, Sh2)).Select


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Steve" wrote in message
...
Is there a way to write code to select sheets 1 to x number of
sheets? I
have code that is counting the number of sheets in a workbook
and subtracting
3 of those sheets already which is working.

What I want to do is select the sheets and copy to a new
workbook.

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Selecting more than one sheet

Thanks for the quick reply. This will work if I want to select 2 sheets but
it does not allow me to select a range of worksheets, i.e. - Sheet1, Sheet2,
....., Sheet 23.


"Chip Pearson" wrote:

Steve,

Try something like the following:

Dim Sh1 As String
Dim Sh2 As String

Sh1 = "Sheet1"
Sh2 = "Sheet3"
Sheets(Array(Sh1, Sh2)).Select


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Steve" wrote in message
...
Is there a way to write code to select sheets 1 to x number of
sheets? I
have code that is counting the number of sheets in a workbook
and subtracting
3 of those sheets already which is working.

What I want to do is select the sheets and copy to a new
workbook.

Thanks




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Selecting more than one sheet

Hi Steve,

Steve wrote:
Dim Sh1 As String
Dim Sh2 As String

Sh1 = "Sheet1"
Sh2 = "Sheet3"
Sheets(Array(Sh1, Sh2)).Select


Thanks for the quick reply. This will work if I want to select 2
sheets but it does not allow me to select a range of worksheets, i.e.
- Sheet1, Sheet2, ...., Sheet 23.


Something like this may do what you want:

Dim asSheets(22) As String
Dim lSht As Long

For lSht = 1 To 23
asSheets(lSht - 1) = "Sheet" & CStr(lSht)
Next lSht

Sheets(asSheets).Select

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 408
Default Selecting more than one sheet

Hi,

I tried Jake's suggestion and it works great. Is there a way to do it
without declaring the number of elements in the array or setting it as a
variable? I want to use it to select and move up 85 worksheets to another
wookbook and save it. I try setting it at the max, but I keep getting an
error -- Run-time error '9': "Subscript out of range"

--
Regards,
Tim


"Jake Marx" wrote:

Hi Steve,

Steve wrote:
Dim Sh1 As String
Dim Sh2 As String

Sh1 = "Sheet1"
Sh2 = "Sheet3"
Sheets(Array(Sh1, Sh2)).Select


Thanks for the quick reply. This will work if I want to select 2
sheets but it does not allow me to select a range of worksheets, i.e.
- Sheet1, Sheet2, ...., Sheet 23.


Something like this may do what you want:

Dim asSheets(22) As String
Dim lSht As Long

For lSht = 1 To 23
asSheets(lSht - 1) = "Sheet" & CStr(lSht)
Next lSht

Sheets(asSheets).Select

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default Selecting more than one sheet

Hi,

You could make use of the Replace flag.

Sub SelectSheets()

Dim intIndex As Integer
Dim blnReplace As Boolean

blnReplace = True
For intIndex = 2 To 7
Worksheets("Sheet" & intIndex).Select blnReplace
blnReplace = False
Next

End Sub

Cheers
Andy

Steve wrote:
Thanks for the quick reply. This will work if I want to select 2 sheets but
it does not allow me to select a range of worksheets, i.e. - Sheet1, Sheet2,
...., Sheet 23.


"Chip Pearson" wrote:


Steve,

Try something like the following:

Dim Sh1 As String
Dim Sh2 As String

Sh1 = "Sheet1"
Sh2 = "Sheet3"
Sheets(Array(Sh1, Sh2)).Select


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Steve" wrote in message
...

Is there a way to write code to select sheets 1 to x number of
sheets? I
have code that is counting the number of sheets in a workbook
and subtracting
3 of those sheets already which is working.

What I want to do is select the sheets and copy to a new
workbook.

Thanks





--

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
Selecting rows to another sheet Muskrat24 Excel Worksheet Functions 2 June 23rd 09 05:04 PM
Selecting sheet with VB RobN[_2_] Excel Discussion (Misc queries) 14 May 23rd 08 01:36 AM
Selecting Last Sheet Bonbon Excel Worksheet Functions 17 February 22nd 06 04:16 PM
Selecting sheet Fernando Gomez Excel Programming 0 September 2nd 04 03:50 PM
Selecting a sheet by code name Dr.Schwartz Excel Programming 2 August 25th 04 03:34 PM


All times are GMT +1. The time now is 03:22 PM.

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"