Hidden sheet problem(VBA)

AllenL

Board Regular
Joined
Mar 14, 2002
Messages
67
I have this code

Sub SearchAllSheets()
For Each Worksheet In Worksheets
Sheets(Worksheet.Name).Select
Call Main
Next Worksheet
End Sub

which runs the macro for each sheet. I have one hidden sheet in the workbook which I don't want it to be run by the macro.
However, when the code reach the hidden sheet I get an error in the line

Sheets(Worksheet.Name).Select

How can I solve this problem???Please help
Thanks in advance
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi Allen

Do you need to select each sheet before running "Main" ? If really yes, then try:

Code:
Sub SearchAllSheets()
Dim Wrksheet As Worksheet
    For Each Wrksheet In Worksheets
        If Wrksheet.Visible = xlSheetVisible Then
           Sheets(Worksheet.Name).Select
        End If
    Call Main
    Next Wrksheet
End Sub
 
Upvote 0
Sorry AllenL
I misunderstood your post.
.Select will hang on a hidden sheet but .Activate will not.
Have a great day
George
 
Upvote 0
Hi George
If I change to Activate. The macro runs the hidden sheet(which I don't want that to happen).

Any more idea?
Thanks in advance
 
Upvote 0
Hello Dave

I am not really sure what's the difference between select the sheet then run "Main" and not select the sheet then run "Main"
All I want to do is to have all the sheet to run "Main" except the hidden sheet
I try your code but it gives me an error on the same line I had before

Sheets(Worksheet.Name).Select

Please Help
Thanks in advance
 
Upvote 0
Try something like this to exclude the sheet.

If Not (sht.Name = "MySheet") Then

Sorry can't write the full code. the boss just came in.

George
 
Upvote 0
Try this

Sub SearchAllSheets()
For Each worksheet In Worksheets
If worksheet.Visible <> 0 Then
Sheets(worksheet.Name).Select
'Your code here
End If
Next worksheet
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,521
Messages
6,114,104
Members
448,548
Latest member
harryls

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