Add worksheets at end

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have some code that prompts users to enter the current month in an input
box, then it checks to see if a worksheet by that name already exists in the
workbook. If it does exist, the subroutine ends, and if it does not exist it
adds a worksheet with the name of the current month. My problem is that it
is adding the new worksheet as the first worksheet and I would like it add it
as the last worksheet. Can someone help me with this? Here is the code I
have so far:

Sub AddMonthWS()
Dim myMonth As String
Dim Sht As Worksheet
myMonth = Application.InputBox(Prompt:="Enter the current month name:",
Title:="Month", _
Type:=2)
On Error Resume Next
Set Sht = ActiveWorkbook.Worksheets(myMonth)
On Error GoTo 0
If Sht Is Nothing Then
Sheets.Add.Name = myMonth
End If
End Sub

Thanks, Lee
 
Pls Try as follows :-

Sub AddMonthWS()
Dim myMonth As String
Dim Sht As Worksheet
myMonth = Application.InputBox(Prompt:="Enter the current month name:",
Title:="Month", _
Type:=2)
On Error Resume Next
Set Sht = ActiveWorkbook.Worksheets(myMonth)
On Error GoTo 0
If Sht Is Nothing Then
Worksheets.Add after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = myMonth
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top