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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

xld

Banned
Joined
Feb 8, 2003
Messages
5,378
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

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,484
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

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,022
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,190,613
Messages
5,981,939
Members
439,744
Latest member
Lazerbeakk

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
Top