+ Reply to Thread
Results 1 to 16 of 16

looping in filtered range by rows

  1. #1
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    looping in filtered range by rows

    Hi,

    i need to loop in a range I filtered previously in order to find cells based on a conditons.


    Let's say I make a filter like this:

    Please Login or Register  to view this content.
    Now I need to find out, if a column A in each rows in the filtered range has a special value.
    Can you pls help me how to do it?

    Thank you

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

    Re: looping in filtered range by rows

    Unless you got to paste the filter cells in to a range, looping is not going to work. Why? Because when you filter the data, the filtered data is turned in to an "Area". It means, you only get one or two rows, followed by a blank row and then again get one or two rows and pattern continues. In effect, you are looping through an area, not a range.
    Why can not you just loop though the raw data without filtering and find out if each cell in column A has a special value? If you could attach a sample with a desired result, I might have a go.

  3. #3
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Re: looping in filtered range by rows

    I thought it would be easier to make the code to have the filtering first then make the analysis instead of looping the whole range which has 10000 lines
    I also thought it would be quicker, as I have many things to check, but all filter should result a few rows only.

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

    Re: looping in filtered range by rows

    Okay! Let me clarify.
    Yes, you can copy the filtered cells in a range, that is, in to a sheet, then you can loop through each this cells and do the rest.
    However, you can NOT load the filtered cells in an array. If you can, they would be much faster. I do not think, you can avoid a loop, so why do you need to loop twice?

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: looping in filtered range by rows

    You can loop through the filtered range but because it is likely to be made up of non-contiguous areas consisting of one or more rows it's not straightforward.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  6. #6
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Re: looping in filtered range by rows

    I am not sure I totally understand.
    Can you pls clarify how to check if column A in the filtered area = "myvalue"

    Thanks for your help

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: looping in filtered range by rows

    Like this perhaps.
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Re: looping in filtered range by rows

    what I don't understand, what are the types ofar and rw, and how do I know, if rw.value is referencing column A?
    Sorry, the if question is a a bit silly.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: looping in filtered range by rows

    ar and rw are Ranges.

    The outer loop is looping through all the visible areas in the range "$A$1:$A" & lrSource, ie all the visible areas in column A.

    The inner loop is looping through all the rows in each of those areas.

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

    Re: looping in filtered range by rows

    Which bring you back to double looping?

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: looping in filtered range by rows

    I thought the OP wanted to know how to loop through the result of a filter, not avoid double looping.

  12. #12
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Re: looping in filtered range by rows

    Sorry again, I mistyped the source.
    it is not only for column A, but "A:F", let's say. In this case how do I reference a cell within a row?

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: looping in filtered range by rows

    Can you clarify exactly where you are looking for the 'special value'?

  14. #14
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Re: looping in filtered range by rows

    I make the filtering on the header, like A:AT
    Then I need to make a lot of check, like
    If (A="Value1" or A="Value2) And B="Value3" then
    ...

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: looping in filtered range by rows

    Sorry, I don't follow.

    In your original post you said you were looking for a 'special' value in column A of a filtered range.

    Now you seem to want to look for multiple values in column A and/or values in multiple columns.

  16. #16
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    Re: looping in filtered range by rows

    Sorry for the confusion. However, I understood your solution and it completely answers my question, thanks a lot.

+ 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. Issue with Looping Filtered Range of Visible Cells
    By Vinod Krishna.C in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-22-2015, 06:52 PM
  2. [SOLVED] Count of visible rows in a filtered range
    By brucemc777 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-16-2014, 01:17 PM
  3. Count rows of a filtered range
    By newbi004 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-29-2013, 06:30 AM
  4. [SOLVED] Looping the rows of an Array into a one range of rows repeatedly
    By Romulo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-25-2013, 10:54 AM
  5. [SOLVED] Copy first 4 rows of filtered range
    By Charles in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-22-2012, 03:02 PM
  6. Looping through rows in range AND comparing range cells
    By Damask in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-16-2006, 10:30 PM
  7. Define a range containing the first 10 rows of a filtered list
    By Marco in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-07-2005, 09:05 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