+ Reply to Thread
Results 1 to 6 of 6

Cell in named range

Hybrid View

Len Silva Cell in named range 05-01-2022, 10:22 AM
BadlySpelledBuoy Re: Cell in named range 05-01-2022, 11:22 AM
Greg M Re: Cell in named range 05-01-2022, 11:29 AM
Greg M Re: Cell in named range 05-01-2022, 11:40 AM
Len Silva Re: Cell in named range 05-01-2022, 07:38 PM
Greg M Re: Cell in named range 05-01-2022, 09:29 PM
  1. #1
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Cell in named range

    Hi there,

    Take a look at the attached workbook and see if it does what you need. It uses the following code:

    
    
    
    Option Explicit
    
    
    Sub CheckCell()
    
        Dim vaRangeNames    As Variant
        Dim sCellAddress    As String
        Dim sRangeNames     As String
        Dim rActiveCell     As Range
        Dim iRangeNo        As Integer
        Dim wks             As Worksheet
    
        If TypeOf Selection Is Range Then
    
              If Selection.Cells.CountLarge = 1 Then
    
                    vaRangeNames = Array("ptrRange_A", "ptrRange_B", "ptrRange_C")
    
                    Set rActiveCell = ActiveCell
                    Set wks = ActiveSheet
                    sCellAddress = rActiveCell.Address(ColumnAbsolute:=False, _
                                                       RowAbsolute:=False)
    
                    sRangeNames = vbNullString
    
                    For iRangeNo = LBound(vaRangeNames) To UBound(vaRangeNames)
    
                        If Not Intersect(rActiveCell, _
                                         wks.Range(vaRangeNames(iRangeNo))) Is Nothing Then
    
                            sRangeNames = sRangeNames & vbLf & vbTab & vaRangeNames(iRangeNo)
    
                        End If
    
                    Next iRangeNo
    
                    If sRangeNames <> vbNullString Then
    
                          MsgBox "Cell " & sCellAddress & " intersects with the " & _
                                 "following named range(s):" & vbLf & sRangeNames, _
                                  vbInformation
    
    
                    Else: MsgBox "Cell " & sCellAddress & " does not intersect with " & _
                                 "any of the specified named ranges", vbInformation
    
                    End If
    
              Else: MsgBox "Please select a single cell before using this feature", vbExclamation
    
              End If
    
        Else: MsgBox "Please select a cell before using this feature", vbExclamation
    
        End If
    
    End Sub
    The highlighted values may be altered to suit your requirements.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

+ 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. Replies: 1
    Last Post: 10-28-2019, 04:14 PM
  2. Listbox displaying named range B but Adding named range A to cell
    By ikkenieikke in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-05-2018, 02:27 PM
  3. [SOLVED] Assign named range to one cell depending on named range in another
    By x65140 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-22-2015, 11:04 AM
  4. [SOLVED] determining if cell is part of named range and what that named range is
    By stnkynts in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-16-2014, 07:56 PM
  5. [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
  6. Replies: 1
    Last Post: 06-03-2006, 10:55 PM
  7. [SOLVED] If any cell in named range = 8 then shade named range
    By JJ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-26-2005, 07: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