简体   繁体   中英

Excel, To find a cell based on its value then find another cell starting the search from the previously found cell position

I have a huge excel sheet that i need to extract some data from...

To simplify what exactly i want to do i'll provide a simple example...

Excel工作表范例

Now allow me to explain what is this and what i am looking to achieve...

In the image the first table to the left contains the following:

B1/B2/B3 which stands for Building 1, 2 and 3 Each building contains 3 floors, F1/F2/F3 Each floor have 3 different tasks that are in progress, T1/T2/T3 In front of each task there are two values V1/V2 which are planned progress and actual progress for the task respectively.

On the right table i want to extract all the values for Task 1 (T1) from the left table for all Buildings and all Floors...

The first thought would be to do a manual extraction by linking each cell on right table with its corespondent on left table, but, with hundreds of buildings and 20th or 30th of floors and 10th of tasks this manual extraction seems like a month work...

The other way is to do that automatically by finding each task and extracting its data to the new table, however there is a huge problem here...

Each similar task is named the same so there are nine T1 and nine T2 and nine T3 in our example. And same goes for the floors there are three of each...

The only thing that is unique are the Buildings B1/B2/B3

So my question is, (explaining what i had in mind):

Is there a way to run a search for lets say in our example B2 (which is Building 2) and once it is found it starts another search from this position (A14) and down looking for 'the first only occurrence' of F2 (which is Floor 2) (so it does not find F2 for Building 3 as well) and once it is found it starts a new search from This B2/F2 position (A19) and down looking for 'the first only occurrence' of T1 (which is Task 1) and then when it is found it extract the numbers in front of it (lets say the one under the second value V2) and place it in the right table which is the Task 1 table (T1) under V2 for B2 in front of F2.

How to achieve that?, what would be the formula or whatever that should be in M5 in our example to get this job done? if it is even possible by a way or another!

Thanks for your help in advance, Best Regards.

The formula for M5 would be (entered as an array formula using ctrl + shift + enter ):

=INDEX($B:$C,MATCH($I$1,IF(ROW($A:$A)>MATCH($I5,IF(ROW($A:$A)>MATCH(IF(M$2="",L$2,M$2),$A:$A,0),$A:$A),0),$A:$A),0),MATCH(M$3,$B$1:$C$1,0))

This can be copied to fill in the rest of the table.

EDIT You can make it faster by limiting it to specific ranges instead of whole columns:

=INDEX($B$1:$C$39,MATCH($I$1,IF(ROW($A$1:$A$39)>MATCH($I5,IF(ROW($A$1:$A$39)>MATCH(IF(M$2="",L$2,M$2),$A$1:$A$39,0),$A$1:$A$39),0),$A$1:$A$39),0),MATCH(M$3,$B$1:$C$1,0))

EDIT2: A quick explanation on the nested MATCH formulas: Start with the third MATCH , MATCH(IF(M$2="",L$2,M$2),$A:$A,0) . This finds the row in column A that contains "B2" (14), so the formula becomes.

=INDEX($B:$C,MATCH($I$1,IF(ROW($A:$A)>MATCH($I5,IF(ROW($A:$A)>14,$A:$A),0),$A:$A),0),MATCH(M$3,$B$1:$C$1,0))

The "14" is used in the comparison for the second IF , which will return all the values in column A as an array except the first 14 rows, which will be FALSE in the array. The second MATCH can then find the first instance of "F2" in that array (19). The formula is now:

=INDEX($B:$C,MATCH($I$1,IF(ROW($A:$A)>19,$A:$A),0),MATCH(M$3,$B$1:$C$1,0))

Repeat the same process as before to get the row of the first instance of "T1" after row 19. This is the row fed to INDEX . The last MATCH gives the column for INDEX .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM