Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Add worksheets at end

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Add worksheets at end

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How use info in Excel shared worksheets to create new worksheets dkc Excel Worksheet Functions 0 June 28th 07 08:36 PM
How do i assign the ActiveWorkbook.Worksheets to a worksheets object? TS Excel Worksheet Functions 2 December 27th 06 02:49 PM
Assigning Cells in worksheets to other data in other worksheets. David McRitchie Excel Discussion (Misc queries) 0 November 27th 04 06:15 PM
Sort Numerically Worksheets via VB when creating a new worksheets John Excel Programming 6 June 1st 04 07:21 AM
Need code to protect worksheets - amount of worksheets varies Sandy[_3_] Excel Programming 1 September 9th 03 02:17 AM


All times are GMT +1. The time now is 01:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"