Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Selection in range? (EXCEL VBA)

    User selects cell. I want to know in VBA if that cell is within a certain range. Of course I can compare to see if row# is in range and column# is in range but I wanted simpler test. So I found (application.)"Intersect". Regretfully I cannot get that to work... anyone with a better / the right oneliner to do that? Note: the range is named, therefore I'd looking for something like:

    IF something(ActiveCell, MyRange)=Whatever (e.g. Empty) then ... else ...

    Thanks,

    Erik Jan

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Selection in range? (EXCEL VBA)

    Erik Jan,

    You can test if the intersection is Nothing, e.g.

    If Intersect(ActiveCell, Range("C1:E3")) Is Nothing Then
    MsgBox "ActiveCell is NOT within range"
    Else
    MsgBox "ActiveCell is within range"
    End If

    Note that the test is "Is Nothing", not "= Nothing".

  3. #3
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selection in range? (EXCEL VBA)

    Yeah... that works. I'm sorry, I don't know what I did wrong.... (I did use IS i.s.o. =) .... Anyway... it's solved ;-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •