I'm having trouble with renaming a worksheet in VBA.
I'm writing a Sub that needs to check if there is a worksheet in the workbook that has a specific name, and if there isn't then make a new sheet with this name. I get the runtime error 1004 application defined or object defined error. I'm hoping anyone can help me. Here is my code:
Dim ws As Worksheet Dim ArrayElement As Variant Dim Current_Tabs(1 To 10) As String NumberNewTab = 1 Tab_Name_Current_Game = Echt_team1 + "vs. " + Echt_team2 For Each ws In Worksheets 'For every worksheet in this workbook Found = False For Each ArrayElement In Current_Tabs array If Tab_Name_Current_Game = ArrayElement Then Worksheets(ws).Activate Worksheets.Select Found = True End If Next ArrayElement If Found = False Then Worksheets.Add Sheets(1).Name = Tab_Name_Current_Game **'Here I get the error** Current_Tabs(NumberNewTab) = Tab_Name_Current_Game NumberNewTab = NumberNewTab + 1 End If Next ws
If I use Sheets(1).Name = "Test"
then I don't run into errors. I don't get why this would be a problem for VBA. Hoping someone can help me. Thank you!
Tab_Name_Current_Game = Echt_team1 & "vs. " & Echt_team2
– luke_tarray
in this line:For Each ArrayElement In Current_Tabs array
? It should not compile. – mielk