PhosFeedLogisticsMan
New Member
- Joined
- Aug 9, 2017
- Messages
- 17
I am relatively new to VBA. Getting Run time error 1004: That name already taken. Try a different one.
Here is what I have, I just recently added the Loop, but I don't think I need it, and believe its something simple I am missing or don't understand.
Quick Background- Looks at a separate worksheet, all data in column A and will be adding to this column as needed as new (SCAC codes) are added. I will need to delete all of these worksheets (in order for something else in my wb to work), then add this list back again as new sheets when I am done(using that sheet called SCAC_Codes). When I run what I have... it will go down the list until it hits an existing named sheet and tell me it exists, and then stop/debug. I want the code to not add it because it exist, but keep going down the column and adding the rest until it gets to the end(blank cell). Then stop. Hope this is not to much info, and that someone can find a simple solution, as I know it is something easily fixed.
Sub RenameSheet()Application.ScreenUpdating = False
Sheets("SCAC_Codes").Activate
Dim myCell As Range, MyRange As Range
Set MyRange = Sheets("SCAC_Codes").Range("A1")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
For Each myCell In MyRange
Sheets.Add After:=Sheets(Sheets.Count) 'creates a new worksheet
Sheets(Sheets.Count).Name = myCell.Value ' renames the new worksheet
Do Until IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
Next myCell
If ActiveSheet.Range("A1").Value = "" Then Exit Sub
Application.ScreenUpdating = True
End Sub
Here is what I have, I just recently added the Loop, but I don't think I need it, and believe its something simple I am missing or don't understand.
Quick Background- Looks at a separate worksheet, all data in column A and will be adding to this column as needed as new (SCAC codes) are added. I will need to delete all of these worksheets (in order for something else in my wb to work), then add this list back again as new sheets when I am done(using that sheet called SCAC_Codes). When I run what I have... it will go down the list until it hits an existing named sheet and tell me it exists, and then stop/debug. I want the code to not add it because it exist, but keep going down the column and adding the rest until it gets to the end(blank cell). Then stop. Hope this is not to much info, and that someone can find a simple solution, as I know it is something easily fixed.
Sub RenameSheet()Application.ScreenUpdating = False
Sheets("SCAC_Codes").Activate
Dim myCell As Range, MyRange As Range
Set MyRange = Sheets("SCAC_Codes").Range("A1")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
For Each myCell In MyRange
Sheets.Add After:=Sheets(Sheets.Count) 'creates a new worksheet
Sheets(Sheets.Count).Name = myCell.Value ' renames the new worksheet
Do Until IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
Next myCell
If ActiveSheet.Range("A1").Value = "" Then Exit Sub
Application.ScreenUpdating = True
End Sub