+ Reply to Thread
Results 1 to 2 of 2

How to copy a sheet and move it to 2nd last (with VBA)

  1. #1
    Brad K.
    Guest

    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. #2
    Rob van Gelder
    Guest

    Re: 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 Before:=Worksheets(i)
    Worksheets(i).Name = CStr(lngMax + 1)
    End Sub


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


    "Brad K." <[email protected]> wrote in message
    news:[email protected]...
    >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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1