PDA

View Full Version : Solved: Macro to insert new worksheet



QuickDraw
12-08-2005, 10:34 AM
This will insert a new worksheet after sheet 1. But how do you add a new ws to the end?
Worksheets.Add after:=Worksheets(1)

Zack Barresse
12-08-2005, 10:43 AM
You just specify that in the After portion ..

Worksheets.Add After:=Worksheets(Worksheets.Count)

austenr
12-08-2005, 10:45 AM
Try this link. I think it will help.

http://www.functionx.com/excel/vba/Lesson07.htm

lucas
12-08-2005, 10:45 AM
Try this QuickDraw

Dim TotalSheets As Variant
TotalSheets = Worksheets.Count
Sheets("Invoice").Select
Sheets("Invoice").Copy After:=Worksheets(TotalSheets)

Amanda1
12-08-2005, 10:46 AM
Sheets("Sheet***").Move After:=Sheets(123)

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.:yes

lucas
12-08-2005, 10:50 AM
Sorry,

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


Dim TotalSheets As Variant
TotalSheets = Worksheets.Count
Worksheets.Add After:=Worksheets(TotalSheets)

QuickDraw
12-08-2005, 11:02 AM
Thanks for all of the responses... worksheets.count is what I needed.

Cheers http://vbaexpress.com/forum/images/smilies/001.gif

Zack Barresse
12-08-2005, 11:03 AM
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..

lucas
12-08-2005, 11:06 AM
Of course your right Zack......sorry if I confused the issue