Hi I am trying to create a loop to see if an input matches an existing sheet's name.
If it does, then I want the sub to restart (So the user is asked for a new state).
If the input does not have a match, then I want a new sheet to be added. I have most of it done, but when it creates a new sheet, it r-eloops and just adds blank sheets.
Please let me know your thoughts!!
Sub partA()
Dim State As Worksheet
Dim StateName As String
Dim NameExist As Boolean
Dim HQ As String
Dim BO As Integer
Dim Sales As Integer
On Error Resume Next
'Asking for sheet name and then adding one if there is no match
StateName = InputBox("Please Enter a State Name", "State Name")
For Each State In ActiveWorkbook.Worksheets
If UCase(StateName) = UCase(State.Name) Then
NameExist = True
MsgBox "Worksheet " & StateName & " Exists"
ElseIf NameExist = False Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = StateName
End If
Next State
End Sub