+ Reply to Thread
Results 1 to 14 of 14

If not Intersect multiple ranges

  1. #1
    Registered User
    Join Date
    11-05-2007
    Posts
    54

    If not Intersect multiple ranges

    I have the below code "begining"

    Please Login or Register  to view this content.
    What I want to do is use multiple ranges like so:

    Please Login or Register  to view this content.

    However, I want different vba dependant on which of the above triggers.


    So.

    If Range("A2:A100") triggers,

    Do this

    If Range("D2:D100") triggers,

    Do That



    Something like the above.


    Or do I run two completely seperate
    "Private Sub Worksheet_Change(ByVal Target As Range)" .........

    In one sheet?
    Last edited by karl1985; 10-29-2010 at 05:30 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: If not Intersect multiple ranges

    What happens if the Target Intersects both B and D ? Which takes precedence or would you be looking to both "Do This" and "Do That" ?

  3. #3
    Registered User
    Join Date
    11-05-2007
    Posts
    54

    Re: If not Intersect multiple ranges

    how cna it intersect both B & D when the trigger is value change of which you can't change B & D at the same time.

  4. #4
    Registered User
    Join Date
    11-05-2007
    Posts
    54

    Re: If not Intersect multiple ranges

    basically I want two completely different intersect functions. without combining the ranges

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: If not Intersect multiple ranges

    Quote Originally Posted by karl1985 View Post
    how cna it intersect both B & D when the trigger is value change of which you can't change B & D at the same time.
    Create a new sheet - highlight B2:D4 - type 1 and press CTRL + ENTER

    You might say that's convoluted but equally with same range highlighted you can press the Delete key.

    In both cases the Change Event is triggered and in both cases the Target encompasses Columns B & D simultaneously.

  6. #6
    Registered User
    Join Date
    11-05-2007
    Posts
    54

    Re: If not Intersect multiple ranges

    ok point well demonstrated.

    in that case, B comes first.

    maybe if not intersect is not the best method for this???

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: If not Intersect multiple ranges

    If you want the first column to take precedence you can test the column of the resulting Intersect Range

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-05-2007
    Posts
    54

    Re: If not Intersect multiple ranges

    i'll give that a go now

    in the meatime, i'm thinking

    i've got

    Please Login or Register  to view this content.

    can I do this or something simular:


    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-05-2007
    Posts
    54

    Re: If not Intersect multiple ranges

    Your answer above is the solution

    Thank you very much.


    Why is it "case 4" ???

    I may want more than 2 instances.

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: If not Intersect multiple ranges

    Quote Originally Posted by karl1985
    in the meatime, i'm thinking
    Given the rule of precedence and what little we know regards subsequent actions (DoThis/DoThat) I think a Select Case approach is likely to prove a pretty effective and simple method code wise.

    Quote Originally Posted by karl1985
    Why is it "case 4"??
    I used the Column Number rather than the letter (D being column 4) - generally easier to work with numbers than letters when coding (IMO)

    You can add additional Cases... if some Columns are to share the same action you can share the Case,

    Please Login or Register  to view this content.
    means Cols D & J are to perform the same (subsequent) action
    Last edited by DonkeyOte; 10-28-2010 at 08:47 AM.

  11. #11
    Registered User
    Join Date
    11-05-2007
    Posts
    54

    Re: If not Intersect multiple ranges

    ok, thanks for that, lets hope they don't insert a column then!

    seriously though, thank you.

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: If not Intersect multiple ranges

    Quote Originally Posted by karl1985 View Post
    lets hope they don't insert a column then!
    If that were the case it follows that given the Intersect references are constant then all approaches are susceptible to error ... ie the fact you're using numbers rather than letter is of no consequence
    (you don't have to use the number if you'd prefer not to)

  13. #13
    Registered User
    Join Date
    11-05-2007
    Posts
    54

    Re: If not Intersect multiple ranges

    ok, interesting.

    How would I use a letter then?

    Obviously 4 = D

    do I just put case D??

    Thanks for your help.

  14. #14
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: If not Intersect multiple ranges

    I stand by my point that numbers are "better" but in general terms you would modify the Select Case

    Please Login or Register  to view this content.

+ 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