+ Reply to Thread
Results 1 to 3 of 3

Simple range question

  1. #1
    Registered User
    Join Date
    02-18-2005
    Posts
    2

    Question Simple range question

    OK, the user has selected a cell named Target. I have pre-defined a range called rng. How can I tell if Target is in rng?

    I ust started looking into VB for Excel today and love what it can do, but I'm stumped on this one (maybe cause it's Friday afternoon...).

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Genevish,

    I have found testing if cell in is in a given more reliable and faster than using strings. Here is how I do it.

    Example:

    Dim R As Long
    Dim C As Long
    Dim RowOK As Boolean
    Dim ColOk As Boolean

    Target = Range"$A$15"
    Rng = "$A$5:$D$15"

    R = Target.Row
    C = Target.Column

    If R >= 5 And R =< 15 Then
    RowOk = True
    Else
    RowOK = False
    End If

    If C >= 1 And C <= 4 Then
    ColOk = True
    Else
    ColOK = False
    End If

    If RowOk = True And ColOk = True Then
    <Execute your code>
    End If


    Hope this helps,
    Leith Ross

  3. #3
    Registered User
    Join Date
    02-18-2005
    Posts
    2

    Thanks

    Thanks for the quick reply. I ended up solving my problem. Your solution occured to me, but there are actually 4 ranges, which made it more difficult. I ended up combining them with a Union, then I searched them with an Intersection. It seems my main problem was not declaring the variables as objects (it's always the simple stuff I have problems with). I'm not worried about performance, as there are only about 50 rows per workbook.

    I'm now mostly done with the template I was working on, but I'm wondering how I can set the default name in the save dialog box. Is it possible?

    Thanks again...

+ 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