I want to check if the sheet named "test" exists and if not, create and name that sheet to "test".
If it exists, I run a separate block of code which I haven't put up here. I have used error handling in that it ignores the error if it happens.
If Sheets("test").Name = "" Then
'MsgBox Sheets("test").Name & "Name"
.Worksheets.Add After:=ThisWorkbook.Worksheets("test2")
.ActiveSheet.Name = "test"
End If
No matter what I do, this section of the code always runs and creates a new sheet.
The code runs properly if the sheet "test" doesn't exist already. It creates a new sheet and renames it and moves on. Obviously it doesn't rename the sheet in the other case since there's already another sheet "test" with the same name.