avoiding hidden sheets with sheet naming

egris52788

Board Regular
Joined
Mar 6, 2003
Messages
114
How do I get this sheet tab naming macro to avoid hidden sheets. I want it to only name the unhidden sheets?


Sub NameSheetss()
Dim I As Long
Dim ws As Worksheet
I = 1
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Sheet Names" Then ws.Name = Sheets("Sheet Names").Cells(I, 1)
I = I + 1
Next ws
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Code:
Sub NameSheetss()
Dim I As Long
Dim ws As Worksheet
    I = 1
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Visible = clseheetvisible Then
            If ws.Name <> "Sheet Names" Then
                ws.Name = Sheets("Sheet Names").Cells(I, 1)
            End If
        End If
        I = I + 1
    Next ws
End Sub
 
Upvote 0
Sub NotVisiblesheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If Not ws.Visible = True Then
MsgBox "Your Sheet " & ws.Name & " is hidden"
End If
Next
End Sub
 
Upvote 0
In case Sheet Names contains invalid sheet names (or has blanks in column A)

Code:
Sub NameSheets()
Dim I As Long, ws As Worksheet
I = 1
For Each ws In ActiveWorkbook.Worksheets
    If ws.Visible = xlSheetVisible And ws.Name <> "Sheet Names" Then
        On Error Resume Next
        ws.Name = Sheets("Sheet Names").Cells(I, 1)
        On Error GoTo 0
    End If
    I = I + 1
Next ws
End Sub
 
Upvote 0
Actually, if I had a ¡DOH! emoticon, I woulda used it. I myself have made that exact recommendation (adding the RESUME NEXT/GOTO 0 around a worksheet rename) on probably a dozen threads over the years.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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