+ Reply to Thread
Results 1 to 2 of 2

Help! Question about Worksheets.Copy

  1. #1
    Registered User
    Join Date
    02-23-2006
    Posts
    3

    Help! Question about Worksheets.Copy

    All the the code works except I need the new sheets to be copied from the sheet named template. Here is the code.

    Sub add_sheets()

    Dim wks As Worksheet
    Dim rng As Range
    Dim LastRow As Long
    Dim I As Long

    LastRow = Sheets("Summary").Range("A" & Rows.Count).End(xlUp).Row

    For I = 1 To LastRow
    Set rng = Sheets("Summary").Range("A" & I)
    Set wks = Worksheets.Add(After:=Worksheets(Worksheets.Count - 1))
    wks.Name = rng.Value
    Next I

    Sheets("Summary").Select
    Range("A1").Select

    End Sub

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    I tried this but it doesnt work.

    Sub add_sheets_test()

    Dim wks As Worksheet
    Dim rng As Range
    Dim LastRow As Long
    Dim I As Long

    LastRow = Sheets("Summary").Range("A" & Rows.Count).End(xlUp).Row

    For I = 1 To LastRow
    Set rng = Sheets("Summary").Range("A" & I)
    Set wks = Worksheets("Template").Copy(After:=Worksheets(Worksheets.Count - 1))
    wks.Name = rng.Value
    Next I

    Sheets("Summary").Select
    Range("A1").Select

    End Sub

    Any suggestions?

  2. #2
    Tom Ogilvy
    Guest

    Re: Help! Question about Worksheets.Copy

    Sub add_sheets()

    Dim wks As Worksheet
    Dim rng As Range
    Dim LastRow As Long
    Dim I As Long

    LastRow = Sheets("Summary").Range("A" & Rows.Count).End(xlUp).Row

    For I = 1 To LastRow
    Set rng = Sheets("Summary").Range("A" & I)
    Worksheets("Master").Copy After:=Worksheets(Worksheets.Count - 1)
    set wks = ActiveSheet
    wks.Name = rng.Value
    Next I

    Sheets("Summary").Select
    Range("A1").Select

    End Sub

    --
    Regards,
    Tom Ogilvy


    "bigfatdummy" <bigfatdummy.23rgam_1140829801.4576@excelforum-nospam.com>
    wrote in message
    news:bigfatdummy.23rgam_1140829801.4576@excelforum-nospam.com...
    >
    > All the the code works except I need the new sheets to be copied from
    > the sheet named template. Here is the code.
    >
    > Sub add_sheets()
    >
    > Dim wks As Worksheet
    > Dim rng As Range
    > Dim LastRow As Long
    > Dim I As Long
    >
    > LastRow = Sheets("Summary").Range("A" & Rows.Count).End(xlUp).Row
    >
    > For I = 1 To LastRow
    > Set rng = Sheets("Summary").Range("A" & I)
    > Set wks = Worksheets.Add(After:=Worksheets(Worksheets.Count - 1))
    > wks.Name = rng.Value
    > Next I
    >
    > Sheets("Summary").Select
    > Range("A1").Select
    >
    > End Sub
    >
    > XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    >
    > I tried this but it doesnt work.
    >
    > Sub add_sheets_test()
    >
    > Dim wks As Worksheet
    > Dim rng As Range
    > Dim LastRow As Long
    > Dim I As Long
    >
    > LastRow = Sheets("Summary").Range("A" & Rows.Count).End(xlUp).Row
    >
    > For I = 1 To LastRow
    > Set rng = Sheets("Summary").Range("A" & I)
    > Set wks =
    > Worksheets("Template").Copy(After:=Worksheets(Worksheets.Count - 1))
    > wks.Name = rng.Value
    > Next I
    >
    > Sheets("Summary").Select
    > Range("A1").Select
    >
    > End Sub
    >
    > Any suggestions?
    >
    >
    > --
    > bigfatdummy
    > ------------------------------------------------------------------------
    > bigfatdummy's Profile:

    http://www.excelforum.com/member.php...o&userid=31876
    > View this thread: http://www.excelforum.com/showthread...hreadid=516431
    >




+ 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