+ Reply to Thread
Results 1 to 6 of 6

Need correct syntax for ranges

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-30-2008
    Location
    Eau Claire, WI
    Posts
    184

    Need correct syntax for ranges

    What is the correct syntax if I want to replace two named ranges below to Rng and Rng2 in my code? Thanks!

    If Not Intersect(Target, Range("F17:F116,K17:K116")) Is Nothing Then
    Last edited by jman0707; 11-24-2008 at 05:24 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    If Not Intersect(Rng1, Rng2) Is Nothing Then
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    09-30-2008
    Location
    Eau Claire, WI
    Posts
    184
    Thanks shg! Target needs to be in there somewhere as well though. So right now if the target either intersects F17:F116 OR K17:K116, then it runs. So can I put

    If Not Intersect(Target, Rng1, Rng2) Is Nothing Then
    Or will that only run if they all 3 intersect (which can't happen)?

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

    All the range arguments in the Application.Intersect function have to share at least one or more cells in common for a range to be returned that represents the cells that overlap. Since Rng1 and Rng2 are fixed, target, which can vary, will determine the result.
      If Not Intersect(Target, Rng1, Rng2) Is Nothing Then
    Sincerely,
    Leith Ross

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    To test if Target is in Rng1 or Rng2 (or both),
    If Not Intersect(Target, Union(Rng1, Rng2) ) Is Nothing Then
    Last edited by shg; 11-24-2008 at 04:26 PM.

  6. #6
    Forum Contributor
    Join Date
    09-30-2008
    Location
    Eau Claire, WI
    Posts
    184
    OK. I got it to work with the union formula. Thanks!

+ 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