+ Reply to Thread
Results 1 to 8 of 8

how does thi code do what it does?! If Not Intersect.....

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-10-2014
    Location
    Sheffield
    MS-Off Ver
    Excel 2010
    Posts
    180

    how does thi code do what it does?! If Not Intersect.....

    I know what the result of this code is but I don't understand the terms/syntax. Can someone, explain in layman's terms what it's doing please?

    If .AutoFilterMode = True Then
            If Not Intersect(.AutoFilter.Range, .Range("F18")) Is Nothing Then
                .Range("$A$18:$BQ$1000").AutoFilter Field:=.Range("F:F").Column
            End If
        End If
    End With
    Thanks
    MissDB

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: how does thi code do what it does?! If Not Intersect.....

    In effect, it means if you multiply two negative numbers, you get a positive answer. So, "Not" and "Nothing" could be interpreted as "Match". If the two range meet(Intersect), do the lines after the meet.

  3. #3
    Forum Contributor
    Join Date
    03-10-2014
    Location
    Sheffield
    MS-Off Ver
    Excel 2010
    Posts
    180

    Re: how does thi code do what it does?! If Not Intersect.....

    Sorry I still don't understand. I know that this code looks to see if there is a filter on range F18 and then clears it but how is it actually doing this? What does the Intersect bit do?

  4. #4
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: how does thi code do what it does?! If Not Intersect.....

    Intersect can be looked at like a crossroads on the road. If not intersect is nothing translates into, if one car driving across the crossroads doesn't crash into the car driving up or down the crossroads, then do nothing. So if the Cell F8 is in the autofilter range and you enter something in it, the cars crashed, so do something. If something is entered in another cell, the cars didn't crash, so do nothing.
    Does that help?

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: how does thi code do what it does?! If Not Intersect.....

    You have two ranges(or cells), that is AutoFilter.Range and Range("F18"). When these two lines( Ranges) intersect (meet) then do the rest of the code. If they do not intersect, nothing will happen and the code jumps to the next if. I hope it is now clear.

  6. #6
    Forum Contributor
    Join Date
    03-10-2014
    Location
    Sheffield
    MS-Off Ver
    Excel 2010
    Posts
    180

    Re: how does thi code do what it does?! If Not Intersect.....

    So, if there is a filter applied to F18 it will un-filter, if not it will leave as is?

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: how does thi code do what it does?! If Not Intersect.....

    You have two Ifs. If the auto filter is on is the first (if test) which is nothing to do with the second if statement, but if the filter is off, that is, if the return is false on the first if statement, the code will not test the second(meet) line. In other words, both ifs statements need to return true in order for the code to run. In order the code to run from for A-Z, the filter should be on and second test if the two range intersect, If Not Intersect(.AutoFilter.Range, .Range("F18")) Is Nothing Then. Other wise the code returns false.
    Last edited by AB33; 06-09-2016 at 05:21 AM.

  8. #8
    Forum Contributor
    Join Date
    03-10-2014
    Location
    Sheffield
    MS-Off Ver
    Excel 2010
    Posts
    180

    Re: how does thi code do what it does?! If Not Intersect.....

    Thank you all very much. Very helpful. I think I've got it now! I love this site :-)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need to add 0 where Value X and Value Y intersect
    By cmtgrame in forum Excel General
    Replies: 3
    Last Post: 05-14-2014, 12:57 PM
  2. intersect function code
    By mubashar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2014, 01:05 AM
  3. [SOLVED] Modifying code "If Not Intersect" with Else (2007)
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2013, 10:48 AM
  4. Can I add another Else to this intersect?
    By lastat in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-17-2010, 04:41 PM
  5. If Intersect
    By astanix in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-02-2010, 05:56 PM
  6. Difference between Intersect and Not Intersect is Nothing
    By batman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-13-2009, 05:39 PM
  7. Intersect in VBA
    By mattydalton in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-30-2009, 08:15 AM

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