+ Reply to Thread
Results 1 to 6 of 6

determining if cell is part of named range and what that named range is

Hybrid View

stnkynts determining if cell is part... 08-16-2014, 11:34 AM
Vikas_Gautam Re: determining if cell is... 08-16-2014, 11:48 AM
Vikas_Gautam Re: determining if cell is... 08-16-2014, 11:55 AM
jaslake Re: determining if cell is... 08-16-2014, 12:47 PM
mikerickson Re: determining if cell is... 08-16-2014, 01:03 PM
stnkynts Re: determining if cell is... 08-16-2014, 07:56 PM
  1. #1
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    determining if cell is part of named range and what that named range is

    Ok, I got one I can't seem to figure out.

    Let's say you have a named range, Rng1, which consists of cells A1 & A2. In vba how would you report back what, if any, named range the following cells resides:

    Cells(1, 1)
    '  Looking for a way so that this cell reference would identify that it is part of Rng1
    Note: There are multiple named ranges so using intersect is not feasible. Essentially, through code, I will be given a range and I need to determine if that range if part of a named range.

    If this doesn't make sense or you need an example workbook please let me know. Thanks.
    Last edited by stnkynts; 08-16-2014 at 11:36 AM.

  2. #2
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: determining if cell is part of named range and what that named range is

    of course workbook is needed, and little more explanation as well..

    Don't forget to click *

  3. #3
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: determining if cell is part of named range and what that named range is

    however you can try this..

    IF cells(1,1).row>Rng1.row AND cells(1,1).row<Rng1.rows(rng1.rows.count).row AND _
     cells(1,1).column>Rng1.column AND cells(1,1).column<Rng1.columns(rng1.columns.count).column THEN
    
    your code...
    
    END IF

    a bit lengthy, but will do the job...

    Don't forget to click *

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: determining if cell is part of named range and what that named range is

    Hi stnkynts

    Something like this
    Sub RangeNames()
    'http://www.mrexcel.com/forum/excel-questions/875-visual-basic-applications-cell-given-range.html
      Dim nm As Name
      For Each nm In ActiveWorkbook.Names
        If Not Intersect(Cells(1, 1), nm.RefersToRange) Is Nothing Then
          MsgBox nm.Name
        End If
      Next
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: determining if cell is part of named range and what that named range is

    You could do something like this
    Dim oneName As Name
    Dim testCell As Range
    
    Set testCell = Range("A5")
    
    On Error Resume Next
    For Each oneName In ThisWorkbook.Names
    
        If Not Application.Intersect(oneName.RefersToRange, testCell) Is Nothing Then
            MsgBox testCell.Address & " is in " & oneName.Name & vbCr & _
                    "which address is " & oneName.RefersToRange.Address
        End If
    
    Next oneName
    On Error GoTo 0
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: determining if cell is part of named range and what that named range is

    Perfect that is exactly what I was looking for. Thanks.

+ 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. [SOLVED] Determining if the value of a cell can be a named range, then assigning named ranges after
    By Romulo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-15-2013, 06:05 PM
  2. Check if cell is part of a named range
    By RobynC in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-26-2008, 02:31 PM
  3. Find out what named range a cell is part of
    By pizzett in forum Excel General
    Replies: 1
    Last Post: 07-25-2007, 10:44 AM
  4. Determining if a named range exists
    By a in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-05-2006, 09:45 AM
  5. Is the active cell part of a named range
    By Virginia in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-23-2005, 02:07 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