title: Excel add sheet with code after last sheet in Workbook
body: <p>I am adding a sheet each month from a sheet called &quot;Template&quot; and namining it &quot;Month Year&quot;. That all works fine but it places new sheet next to &quot;Template&quot; sheet. I want it to add new sheet after last sheet in workbook. I changed it to Shhet count but get an error. Can you help?
  This is my Code.</p>
  <pre><code>Sub CopySheet()
     Dim MySheetName As String
     
     'MySheetName = ActiveCell.Text
     'OR
     MySheetName = InputBox(&quot;Enter a Sheet Name!&quot;)
    
     'check a value has been entered
     If MySheetName = &quot;&quot; Then
        MsgBox &quot;No sheet name was entered, ending!&quot;
        Exit Sub
     Else
        '================================================
        'Check there are no invalid sheet name characters
        '================================================
        If ValidSheetName(MySheetName) Then
         Sheets.Add.Name = &quot;Template&quot;
  Worksheets(&quot;Template&quot;).Move After:=Worksheets(Worksheets.Count)
        Else
           MsgBox &quot;There is an invalid character in the sheet name!&quot;
        End If
        
   End If
  End Sub
  
  
  
  
  Function ValidSheetName(ByVal sheetName As String) As Boolean
     '========================================
     'check a sheetname for invalid characters
     '========================================
     Dim arrInvalid As Variant
     Dim i As Long
     
     arrInvalid = Array(&quot;/&quot;, &quot;\&quot;, &quot;[&quot;, &quot;]&quot;, &quot;*&quot;, &quot;?&quot;, &quot;:&quot;)
     
     For i = LBound(arrInvalid) To UBound(arrInvalid)
        If InStr(1, sheetName, arrInvalid(i), vbTextCompare) Then
           ValidSheetName = False
           Exit Function
        End If
     Next
     
     ValidSheetName = True
  End Function
  </code></pre>