Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Help! Macro to select all sheet from AA to ZZ

Try this

Sub GroupSheets()

Dim sh As Object
Dim shArr() As String
Dim FirstSheet As Object
Dim LastSheet As Object

Set FirstSheet = Sheets("Sheet2")
Set LastSheet = Sheets("Sheet3")

ReDim shArr(FirstSheet.Index To LastSheet.Index)

For Each sh In ThisWorkbook.Sheets
If sh.Index = FirstSheet.Index And sh.Index <= LastSheet.Index Then
shArr(sh.Index) = sh.Name
End If
Next sh

Sheets(shArr).Select

End Sub

--
Post byDick Kusleika


--
Don Guillett
SalesAid Software

"Elaine Roden" wrote in message
...
How do I write a macro in Excel 2000 that selects all the sheets from

sheet aa to sheet zz. To explain what I need to do, our business is very
seasonal (about 40 year-round and 40 employees that come and go in spring
and fall) and when our employees are laid off, we move their sheets out of
the current section (aa-zz) and only print and update the emplyees that are
currently working. I would like to be able to move sheets in and out of this
group, but have the macro automatically select whatever sheets I have placed
between aa & zz. I am sort of new to Excel. I used to do all my programming
in a different spreadsheet, but the latest versions of it are terribly
unstable and I am converting everything to excel which is much more stable,
but it is a learning curve. (PS. aa and zz are names I gave to the dividing
sheets)

Thanks so much in advance. Your newsgroup is great and I have been able to

find lots of the answers that I need in here already!

Elaine



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Help! Macro to select all sheet from AA to ZZ

When I go into debug, the highlighed error out of range error is on the last line

Sheets(shArr).Selec

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Help! Macro to select all sheet from AA to ZZ

Did you change these lines:

Set FirstSheet = Sheets("aa")
Set LastSheet = Sheets("zz")

If you did, then you'll want to post the code you used. (Don's code worked fine
for me.)

Did you know that you can do the same thing manually by clicking on the AA
worksheet tab, then shift-clicking on the ZZ worksheet tab?



Elaine Roden wrote:

When I go into debug, the highlighed error out of range error is on the last line

Sheets(shArr).Select


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Help! Macro to select all sheet from AA to ZZ

Could have something to do with
ThisWorkbook.Sheets
try
For Each sh In .Sheets
or
For Each sh In activeworkbook.Sheets

--
Don Guillett
SalesAid Software

"Elaine Roden" wrote in message
...
Why is it that every time I type a reply to you, something new occurs to

me to try right after I click send?

I just copied the macro into the particular worksheet VB and it works, it

must be something to do with the fact that I was storing it in the personal
macro library instead of the worksheet macro library.

Any Ideas?

Elaine



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Help! Macro to select all sheet from AA to ZZ

And just add to Don's excellent detective work:

ThisWorkbook refers to the workbook containing the code. If you put the code in
your personal.xls workbook, then those sheets would have to be that personal.xls
workbook.

By suggesting Activeworkbook, Don says to run the code against the, er,
activeworkbook.

(now that last sentence was quite helpful, huh?)



Elaine Roden wrote:

Why is it that every time I type a reply to you, something new occurs to me to try right after I click send?

I just copied the macro into the particular worksheet VB and it works, it must be something to do with the fact that I was storing it in the personal macro library instead of the worksheet macro library.

Any Ideas?

Elaine


--

Dave Peterson

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
Select dynamic data in 2 columns, and repeat macro to next sheet Tasha Excel Discussion (Misc queries) 2 September 17th 09 07:00 PM
Macro to go to select sheet Kevin Excel Discussion (Misc queries) 2 December 18th 07 02:28 AM
macro sheet select Dave K Excel Discussion (Misc queries) 2 October 21st 05 10:08 PM
Macro, select Sheet "Number", NOT Sheet Name DAA Excel Worksheet Functions 4 November 30th 04 05:29 PM
On Sheet select Macro Colin G Eastwood Excel Programming 3 January 21st 04 05:22 PM


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