Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default How to copy a sheet and move it to 2nd last (with VBA)

I have a workbook that will contain variable number of sheets and the sheets
names are numerical but not necessarily consecutive. I am trying to write a
macro that will copy a template sheet and move it to the second last sheet in
the workbook ("Template" sheet) is the final sheet. As mentioned, the new
sheet will have a numerical name (i.e. "15").
Any help is appreciated as I just can't get my head around this.
Thanks in advance,
Brad
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default How to copy a sheet and move it to 2nd last (with VBA)

Sub test()
Dim i As Long, wks As Worksheet, lngMax As Long

For Each wks In Worksheets
If IsNumeric(wks.Name) Then If CLng(wks.Name) lngMax Then lngMax =
CLng(wks.Name)
Next

i = Worksheets.Count
Worksheets("Template").Copy Befo=Worksheets(i)
Worksheets(i).Name = CStr(lngMax + 1)
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Brad K." wrote in message
...
I have a workbook that will contain variable number of sheets and the
sheets
names are numerical but not necessarily consecutive. I am trying to write
a
macro that will copy a template sheet and move it to the second last sheet
in
the workbook ("Template" sheet) is the final sheet. As mentioned, the new
sheet will have a numerical name (i.e. "15").
Any help is appreciated as I just can't get my head around this.
Thanks in advance,
Brad



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
Move or copy sheet Jaleel Excel Discussion (Misc queries) 1 October 18th 07 03:49 PM
a formula or sheet you want to move or copy contains the name xxx michelle Excel Discussion (Misc queries) 1 June 20th 07 06:27 AM
move or copy sheet Cathy Excel Worksheet Functions 2 June 25th 06 05:55 PM
Copy Sheet and move to end Nigel Excel Discussion (Misc queries) 1 August 9th 05 05:09 PM
How do I move or copy more then one sheet at a time Carl Excel Worksheet Functions 2 June 2nd 05 11:42 PM


All times are GMT +1. The time now is 03:21 PM.

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"