Code to always add new sheet after the last sheet

hocs

New Member
Joined
Nov 13, 2009
Messages
33
Hi,

i need some clue to do the following: whenever the macro is run, it will add a new worksheet as the last sheet, nomatter how many existing worksheets there are (i.e. the right most sheet tab will be this new added sheet)

Sub AddLastSheet()
Dim ws as Worksheet
Set ws = worlsheets.Add (ALWAYS AT AS THE LAST WORKSHEET)
End Sub

Thanks!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Code:
    Set ws = Worksheets.Add(After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count))
 
Upvote 0
Code:
    Set ws = Worksheets.Add(After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count))

the next step i wish to do: after adding new sheet, i need to copy the previous sheet content into this new added sheet. cell F3 of the previous sheet is invoice number but for F3 of this new added sheet, this number will have to be increased by 1.
Please advise!
Thanks!
 
Upvote 0
Code:
Sub test()
 
    Sheets(ThisWorkbook.Worksheets.Count).Copy After:=Sheets(ThisWorkbook.Worksheets.Count)
    Range("F3").Value = Range("F3").Value + 1
    ActiveSheet.Name = "Invoice " & Range("F3").Value
 
End Sub
Edit: was previously copying current sheet. Not the last one.
 
Last edited:
Upvote 0
You could copy the entire worksheet.

Code:
ActiveSheet.Previous.Select
Range("First cell:Last cell").Copy
ActiveSheet.Next.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
        :=False, Transpose:=False

Regards,
ArviY2k
 
Upvote 0
I forgot to mention.. Replace first cell and last cell in my code in the above post with your data range.
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,619
Members
449,240
Latest member
lynnfromHGT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top