Select all worksheets

Jonbob

Board Regular
Joined
Feb 6, 2003
Messages
160
I have 200 worksheets in a workbook. What macro is there to select all worksheets?

Thanks,
Jonbob
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I use the following code:

Code:
    Dim Arr() As String
    Dim i As Integer
    ReDim Arr(Sheets.Count - 1)
    For i = 0 To Sheets.Count - 1
        Arr(i) = Sheets(i + 1).Name
    Next i
    Sheets(Arr).Select

I can't take credit for it, but I don't remember who to credit for coming up with it when I was in need of this same feature. Sorry :oops:
 
Upvote 0
Hi BuddieB, you can also do this as the Sheets property also accepts numbers as well as Sheet names. Note that MyArray is declared as an integer rather than a string in this case. :-)

Code:
Sub SelectAllSheets()
Dim MyArray() As Integer, i As Integer
ReDim MyArray(1 To Sheets.Count)

For i = 1 To Sheets.Count
MyArray(i) = i
Next i

Sheets(MyArray).Select

End Sub
 
Upvote 0
parry said:
Sheets property also accepts numbers as well as Sheet names
And with this mind,

<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> test()
Sheets(Evaluate("transpose(row(1:" & Sheets.Count & _
    "))")).<SPAN style="color:darkblue">Select</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>
 
Upvote 0
NateO said:
parry said:
Sheets property also accepts numbers as well as Sheet names
And with this mind,

<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> test()
Sheets(Evaluate("transpose(row(1:" & Sheets.Count & _
    "))")).<SPAN style="color:darkblue">Select</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>

You goys always have to go one better. :-) btw, I think Mudface wins. :-P

Nate, I cant understand this at all even though I have looked Evaluate up under help.
 
Upvote 0
Thanks Nate, Evaluate is something I would have to use a few times for it to sink in properly but I think I understand what you have done now.
 
Upvote 0
You are welcome.

This is one of several potential uses of the Evaluate method mind you.

Enter the following in a worksheet:

=TRANSPOSE(ROW(1:10))

Hit your function wizard to review the return. You're simply cranking out, and using, this array in VBA. :)
 
Upvote 0
Why not use the GUI? Click on the tab of the first worksheet. Click on the VCR button that moves all the way to the right. Hold down SHIFT and click on the tab of the last worksheet.

And, if you must have a VBA solution, use
Code:
Sub testIt()
    ActiveWorkbook.Sheets.Select
    End Sub

Simple, eh? [Edit: I just noticed Mudface has already mentioned it. Oops! :oops: ]

That said...200 worksheets? For the life of me, I cannot envison any business / scientific / education scenario that would require that many worksheets in a single workbook. Mind sharing what you are doing?

Jonbob said:
I have 200 worksheets in a workbook. What macro is there to select all worksheets?

Thanks,
Jonbob
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,637
Members
452,663
Latest member
MEMEH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top