title: Getting a "Subscript out of range" error, and I don't know whats wrong. (I'm kind of new to vba)
body: <p>This is my code:</p>
  
  <pre><code>Private Sub New_User_Create_Click()
  CreateUsername_L = LCase(Create_User_Text.Text)
  For Each ws In Worksheets
      If (Worksheets(CreateUsername_L).Name &lt;&gt; "") Then
          MsgBox "Username is already taken! Try again!"
          Create_User_Text.Text = ""
          NewUser.Hide
          Exit For
      Else
          Dim work As Worksheet
          With ThisWorkbook
          Set worksheetname = .Sheets.Add(After:=Worksheets(Worksheets.Count))
          worksheetname.Name = CreateUsername_L
          On Error Resume Next
          Create_User_Text.Text = ""
          NewUser.Hide
          [B1].Value = (UserName + "'s Personal Profile")
          Exit For
  
          End With
  
      End If
  Next ws   
  End Sub
  </code></pre>
  
  <p>If you could help me with this it would be much appreciated
  (also the error only occurs when the condition is not met e.g there is no sheet with the same name as "CreateUsername_L". When the condition is met the message box with "Username is already taken..." shows up so its only when the condition is not met when this error occurs)</p>