+ Reply to Thread
Results 1 to 5 of 5

Macro to Copy named range of Active cell to another sheet + Name Sheet After Named Range

  1. #1
    Registered User
    Join Date
    04-28-2015
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    61

    Macro to Copy named range of Active cell to another sheet + Name Sheet After Named Range

    Trying to use a Macro That will find the Named range of the selected cell then copy the Said Named range to another Sheet + Name that sheet after the Named range see code below.
    It keeps stopping at " Set rng = Intersect(ActiveCell, Range(nm.Name))"

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Macro to Copy named range of Active cell to another sheet + Name Sheet After Named Ran

    Hello. Try with:

    PHP Code: 
    Option Explicit

    Sub Copy_and_name_new_worksheet
    ()
    Dim nrng As String

    nrng 
    GetNamedRange
    If nrng "" Then MsgBox "ACTIVE CELL IS BLANK": Exit Sub
    If Not Evaluate("ISREF('" nrng "'!A1)"Then
      Sheets
    .Add(, Sheets(Sheets.Count)).Name nrng
      Range
    (nrng).Copy ActiveSheet.Range("A1")
    Else
      
    MsgBox "SHEET EXISTS"
    End If
    End Sub

    Function GetNamedRange() As String
    Dim nm 
    As Name

    For Each nm In ThisWorkbook.Names
      
    If ActiveCell.Parent Is Range(nm.Name).Parent Then
        
    If Not Intersect(ActiveCellRange(nm.Name)) Is Nothing Then
          GetNamedRange 
    nm.Name
          
    Exit Function
        
    End If
      
    End If
    Next
    End 
    Function 
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

  3. #3
    Registered User
    Join Date
    04-28-2015
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    61

    Re: Macro to Copy named range of Active cell to another sheet + Name Sheet After Named Ran

    Seems to be Stopping on the Line

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Macro to Copy named range of Active cell to another sheet + Name Sheet After Named Ran

    That's because 'Range(nm.Name)' is failing and tells you that one of the names defined in the workbook is not a cell range: Check it out!... Upload your workbook to the Forum!

  5. #5
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Macro to Copy named range of Active cell to another sheet + Name Sheet After Named Ran

    .
    You will need to add one more check:

    PHP Code: 
    Function GetNamedRange() As String
    Dim nm 
    As Name
    For Each nm In ThisWorkbook.Names
      
    If Not IsError(Evaluate("Cell(""Row"", " nm.Name ")")) Then
        
    If ActiveCell.Parent Is Range(nm.Name).Parent Then
          
    If Not Intersect(ActiveCellRange(nm.Name)) Is Nothing Then _
            GetNamedRange 
    nm.Name: Exit Function
        
    End If
      
    End If
    Next
    End 
    Function 

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Adjust existing macro to pick up specific named worksheet and copy to named range
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-08-2017, 12:03 PM
  2. Query rows from a named range in active sheet as an array
    By chickpeazy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-31-2017, 12:58 PM
  3. VBA code to find cell contents within named range, copy to new row on another sheet
    By djarum11 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-23-2015, 11:17 PM
  4. [SOLVED] Simple Copy of Named Range to another sheet
    By R.Koenig in forum Excel General
    Replies: 3
    Last Post: 02-11-2013, 02:45 PM
  5. excel macro range define to another sheet / named range
    By koi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2013, 10:25 AM
  6. Finding a named range based on cell value and copy/paste to same sheet?
    By Simon Lloyd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2006, 06:25 PM
  7. [SOLVED] Select Named Range - Active sheet - Message Box address
    By al007 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2005, 03:40 AM

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