Results 1 to 6 of 6

Copy named range "headerrows" to each worksheet as created by named range "classes"

Threaded View

nigelog Copy named range "headerrows"... 09-25-2017, 04:55 AM
xlnitwit Re: Copy named range... 09-25-2017, 05:01 AM
nigelog Re: Copy named range... 09-25-2017, 05:07 AM
xlnitwit Re: Copy named range... 09-25-2017, 05:10 AM
nigelog Re: Copy named range... 09-25-2017, 05:17 AM
xlnitwit Re: Copy named range... 09-25-2017, 05:23 AM
  1. #1
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Copy named range "headerrows" to each worksheet as created by named range "classes"

    The below code works to create worksheets from a dynamic named range "classes". I am trying to add header rows, another named range, as the worksheet is created. The macro does copy the named range "headerrows" but doesn't paste even though the worksheet is correctly named and created.

    Any ideas how to properly reference the newly created worksheet??

    Sub AddSheets()
        Dim xRg As Excel.Range
        Dim wSh As Excel.Worksheet
        Dim wBk As Excel.Workbook
        Dim Classes As String
        Set wSh = ActiveSheet
        Set wBk = ActiveWorkbook
        Application.ScreenUpdating = False
        For Each xRg In wSh.Range("Classes")
    
            With wBk
                .Sheets.Add after:=.Sheets(.Sheets.Count)
                Debug.Print Range("headerrows").Address
                On Error Resume Next
                ActiveSheet.Name = xRg.Value
                Range("headerrows").Copy ActiveSheet("a1").PasteSpecial
                If Err.Number = 1004 Then
                  Debug.Print xRg.Value & " already used as a sheet name"
                End If
                On Error GoTo 0
            End With
        Next xRg
        Application.ScreenUpdating = True
    End Sub
    Last edited by nigelog; 09-25-2017 at 05:18 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to use named ranges in VBA code using "Columns" and a variation on "Range"
    By haljam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2014, 02:48 PM
  2. Replies: 5
    Last Post: 11-04-2013, 11:28 AM
  3. Replies: 2
    Last Post: 08-02-2013, 05:24 PM
  4. Named Range = "CountryA" OR "CountryB"
    By f0urchette in forum Excel General
    Replies: 0
    Last Post: 03-05-2012, 04:20 AM
  5. VBA - Input Value If Column Number Equals "x" within Non-Contiguous Named Range
    By greenexcel12345 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-28-2011, 02:23 PM
  6. Replies: 3
    Last Post: 06-04-2011, 10:56 AM
  7. [SOLVED] Access a worksheet level named range with Refers To like "=5".
    By Jeremy Gollehon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2006, 06:10 PM
  8. macro to remove a named range always called "database" & if possib
    By Todd F. in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-25-2005, 02:05 PM

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