PDA

View Full Version : [SOLVED] Renaming multiple worksheets from list



DeanP
02-08-2019, 06:52 AM
I am adding 3 sheets to my workbook and want to rename each based on a list. I am able to add the 3 sheets, but the renaming from list doesn't work.


Code:

Dim i As Long
With ThisWorkbook
For i = 1 To 3
Worksheets.Add after:=Worksheets(Worksheets.Count)
Sheets(i).Name = Worksheets("Business Structure").Cells(i, 17).Value
Next i
End With
End Sub


Any advice?

Paul_Hossler
02-08-2019, 08:34 AM
After you .Add the sheet, your "I" loop variable still points to the last one, not the one you just added

Try one of these




Sub AddSheets()

Dim i As Long

With ThisWorkbook
For i = 1 To 3
Worksheets.Add after:=Worksheets(Worksheets.Count)
Sheets(i + 1).Name = Worksheets("Business Structure").Cells(i, 17).Value
Next i
End With
End Sub





Sub AddSheets()
Dim i As Long
With ThisWorkbook
For i = 1 To 3
Worksheets.Add after:=Worksheets(Worksheets.Count)
Sheets(Worksheets.Count).Name = Worksheets("Business Structure").Cells(i, 17).Value
Next i
End With
End Sub

DeanP
02-08-2019, 09:23 AM
Amazing! Thank you Paul