+ Reply to Thread
Results 1 to 4 of 4

Determin in which named range is the activecell

Hybrid View

  1. #1
    Forum Contributor stojko89's Avatar
    Join Date
    05-18-2009
    Location
    Maribor, Slovenia
    MS-Off Ver
    MS Office 365
    Posts
    913

    Determin in which named range is the activecell

    Hi,

    Is it possible to determin in which named range is the active cell?
    I'm tryn to use this somehow:
    Dim x As Range, OP1 As Range, OP2 As Range, OP3 As Range, OP4 As Range
    Set PO1 = Range("F11:F26")
    Set PO2 = Range("F28:F34")
    Set PO3 = Range("F36:F50")...
    
    'Find out in which named range the activecell is and then use this
    
    For each x in One Of The Named Ranges
    'And so on
    Is this somehow possible?

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Determin in which named range is the activecell

    Try

    If Not Application.Intersect(ActiveCell, PO1) Is Nothing Then
             MsgBox "in PO1"
         ElseIf Not Application.Intersect(ActiveCell, PO2) Is Nothing Then
              MsgBox "in PO2"
         ElseIf Not Application.Intersect(ActiveCell, PO3) Is Nothing Then
              MsgBox "in PO3"
         End If
    If you like my contribution click the star icon!

  3. #3
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Determin in which named range is the activecell

    Or alternatively

    Dim varRange As Variant
    For Each varRange In Array("F11:F26", "F28:F34", "F36:F50")
        If Not Application.Intersect(Range(varRange), ActiveCell) Is Nothing Then
            MsgBox "In range " & varRange
        End If
    Next varRange

  4. #4
    Forum Contributor stojko89's Avatar
    Join Date
    05-18-2009
    Location
    Maribor, Slovenia
    MS-Off Ver
    MS Office 365
    Posts
    913

    Re: Determin in which named range is the activecell

    I was so close. But got one little part wrong
    But this is how it will do now!
    So thanks for the help.
    Sub testing()
    Dim x As Range, PO1 As Range, PO2 As Range, NR As Range
    Set PO1 = Range("F11:F26")
    Set PO2 = Range("F28:F40")
    
    If Not Intersect(ActiveCell, PO1) Is Nothing Then
        Set NR = PO1
        MsgBox "in PO1"
    ElseIf Not Intersect(ActiveCell, PO2) Is Nothing Then
        Set NR = PO2
        MsgBox "in PO2"
    End If
    End Sub

+ 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