Get start and end row number

时间:2015-12-10 01:50:30

标签: excel excel-formula

I have a worksheet that contains the following data:

  A   |B  
--------
1|DOG |1
2|CAT |1
3|CAT |2
4|CAT |3
5|FROG|1

where column A contains animal kinds and B contains some other data. I need a formula that will tell me which row number a particular animal kind starts and ends at. So for instance if I was looking for CAT I could get the starting row number as 2 and ending row number of 4.

Has anyone got any ideas?

2 个答案:

答案 0 :(得分:1)

I have the following set up:

enter image description here

Put this formula in E2:

=MATCH(D2,A$1:A$4,0)

and this in F2:

=E2+COUNTIF(A$1:A$4,D2)-1

and drag down as needed.

答案 1 :(得分:0)

You will get some good formula answers I'm sure, but also consider a pivot table:

enter image description here

The row column is populated with the formula =ROW(). The pivot table has two value fields; one set to the Min of Row the other to the Max.

It's dynamic and will account for whatever animals you add, especially if your list is in a structured table.