Consulting

Results 1 to 9 of 9

Thread: Solved: Macro to insert new worksheet

  1. #1

    Solved: Macro to insert new worksheet

    This will insert a new worksheet after sheet 1. But how do you add a new ws to the end?
    [VBA] Worksheets.Add after:=Worksheets(1)[/VBA]

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    You just specify that in the After portion ..

    [vba]Worksheets.Add After:=Worksheets(Worksheets.Count)[/vba]

  3. #3
    VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Try this link. I think it will help.

    http://www.functionx.com/excel/vba/Lesson07.htm
    Peace of mind is found in some of the strangest places.

  4. #4
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Try this QuickDraw
    [VBA]
    Dim TotalSheets As Variant
    TotalSheets = Worksheets.Count
    Sheets("Invoice").Select
    Sheets("Invoice").Copy After:=Worksheets(TotalSheets)

    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Regular
    Joined
    Nov 2005
    Posts
    82
    Location
    [VBA] Sheets("Sheet***").Move After:=Sheets(123)[/VBA]

    Hi
    Add this line to your script after adjusting for the name of the sheet you have just created and for the name of the last current sheet - it will then move the sheet you have just made to the end.

    Is this what you wanted?

    Cheers

    Amanda Ps Just wait though, because one of the experts will be laughing at me and leap in to tell you a better way to do it. So hold on.

  6. #6
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Sorry,

    Mine is for copying a sheet to the end....try this for a new sheet using Zacks code too

    [VBA]
    Dim TotalSheets As Variant
    TotalSheets = Worksheets.Count
    Worksheets.Add After:=Worksheets(TotalSheets)
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    Thanks for all of the responses... worksheets.count is what I needed.

    Cheers

  8. #8
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hmm, why even use the variable? Wouldn't it suffice like what I posted above? Now if that variable was to be used again, I could see the use of it..

  9. #9
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Of course your right Zack......sorry if I confused the issue
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •