Hi team,
Code below. I
t is meant to run through the work book and format the Tab name with the name in D6. It has been working fine for a couple months but now it refuses to budge from this error on this line.
There are on 10 names that appear repeatedly.
Code below. I
t is meant to run through the work book and format the Tab name with the name in D6. It has been working fine for a couple months but now it refuses to budge from this error on this line.
There are on 10 names that appear repeatedly.
Rich (BB code):
Sub Tab_name()
Dim ws As Worksheet, wsName$, wsCount%, dict ' $ is short for " As String" and % for " As Integer"
Set dict = CreateObject("Scripting.Dictionary")
For Each ws In Sheets
wsName = ws.Range("D6").Value
wsCount = IIf(dict.Exists(wsName), dict(wsName) + 1, 1)
dict(wsName) = wsCount
If wsCount = 1 Then
ws.Name = wsName
Else
If wsCount = 2 Then Sheets(wsName).Name = wsName & 1 ' optional to rename the previous Ohio sheet to Ohio1
ws.Name = wsName & wsCount
End If
Next ws
End Sub
Last edited by a moderator: