Home » excel » Excel – Search contents of cells in an area (between two specific strings)

Excel – Search contents of cells in an area (between two specific strings)

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m not sure it’s possible to do this on Excel, but I’ll explain the problem here.

I have a file with 60.000 rows and its data is displayed as follows:

T1 T2 T3 T4 T5

X X X X Y

X X X X X

X X X X X

T1 T2 T3 T4 T5

X X X X X

X X X X X

T1 T2 T3 T4 T5

X X X X X

X X X X Y

X X X X X

I want to search a specific column (this case, the last) for a specific string “Y”.

If a “Y” isn’t found in between the headers, the header and the rest of the content is deleted and it continues searching till the next header.

The output would be:

T1 T2 T3 T4 T5

X X X X Y

X X X X X

X X X X X

T1 T2 T3 T4 T5

X X X X X

X X X X Y

X X X X X

The headers are exactly the same and static throughout the file, so I was thinking of using them as reference.

Is it possible to do so?
If so, how?

Thank you!

How to&Answers:

Here’s an array formula method…

  1. With your example data in A1:E11 select F1:F11 and enter this formula with CTRL+SHIFT+ENTER:

    =LOOKUP(ROW(E1:E11),ROW(E1:E11)/(E1:E11="T5"),FREQUENCY(IF(E1:E11="Y",-ROW(E1:E11)),IF(E1:E11="T5",-ROW(E1:E11),0)))
    
  2. You can then paste values and filter for rows containing 0 and delete these rows.

Note: The formula returns the count of rows that contain a Y between the headings. Copying data down around 60,000 rows and updating the formula takes only a few seconds to recalculate.

Snapshot

enter image description here