Home > other >  Conditional filter on 2 different columns of excel
Conditional filter on 2 different columns of excel

Time:09-23

How shall I conditional filter in header1 and header3  columns so that the only row, I see in excel is Header1 having any No in-between x to another x of header3 column? If there is all No in header1 column for header 3's x to next x, then don't show up or unfiltered.

Excel macro or vba code would work too. enter image description here My solution- ​I do a filter on header1 column "yes" and manually copy it to header4. Then filter on header3 column to x and Yes. Manually drag x until yes for the row to row.​

Results should like this

enter image description here

Comment solution- enter image description here

CodePudding user response:

I don't 100% understand your application but if you want a very quick and easy solution, you could add another column, with a formula in it and only use that column to filter.

So you would add a column called "Filter" and then have a formula in it something like:

=IF(A2="YES","SHOW",IF(C2="X",IF(COUNTIF(INDIRECT("A"&ROW(C2) 1&":A"&ROW(C2) IFERROR(MATCH("X",INDIRECT("C"&ROW(C2) 1&":C9000"),0)-1,10)),"YES")<1,"HIDE","SHOW"),E1))

This works by:

  1. Checking if the cells in column A contains "YES" and if so, adding "SHOW" to filter column
  2. Checking if Column C contains "X" and if so;
  3. Checking if any of the cells in column A before the next "X" appears in column C, contain "YES"

I used indirect references, so if you move columns around, you will need to adjust those. I also assumed the max lines in your sheet to be 9000, if its more, you will need to adjust that part too.

If you copy and paste this formula into Cell $E$2 and then fill it down and then you should be able to filter to show only the "SHOW" cells and get what you are after.

If this solves your issue, please upvote this answer and tick it as solved.

Screenshot of example:

enter image description here

  • Related