ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting all sheets (https://www.excelbanter.com/excel-programming/297821-re-selecting-all-sheets.html)

Ron de Bruin

Selecting all sheets
 
Hi Erin

You need a loop

Sub test1()
Dim Arr() As String
Dim N As Long
Dim Sh
N = 0
For Each Sh In ThisWorkbook.Sheets
If Sh.Visible = True Then
N = N + 1
ReDim Preserve Arr(1 To N)
Arr(N) = Sh.Name
End If
Next Sh
ThisWorkbook.Sheets(Arr).Select
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Erin" wrote in message ...
I need a piece of VBA code that will select all visible sheets. When I record a macro, it does it via an array and specifying

each sheet name. But, in my case I don't know how many sheets there are.



Erin[_5_]

Selecting all sheets
 
Thanks, works perfectly!


All times are GMT +1. The time now is 08:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com