vba - Excel count rows between 2 strings -


i need place row headers in column a. vary each page need vba handle this. need count number of rows between 2 cell , serielize headers.

enter image description here

to

enter image description here

so need too

  1. loop thrugh column b
  2. scell = find cell in
  3. samples = count cells in between s , inspector
  4. startcell = scell + 1
  5. loop startcell samples

is correct?

non-vba solution

(personally feel vba unnecessary)

you can use formula starting in a1 , autofill down:

=iferror(if(and(match("s",b:b,0)<match(b1,b:b,0),match("inspector",b:b,0)>match(b1,b:b,0)),iferror(offset(indirect(char(column()+64)&row()),-1,0)+1,1),""),"") 

a few notes:

  1. this work numbers , text
  2. this not work blanks
  3. if value searching not unique, there might unexpected results

now hardcoded "s" , "inspector" in this, can of course change cell reference. lets d1 , e1 (just remember use absolute references $d$1 , $e$1:

=iferror(if(and(match($d$1,b:b,0)<match(b1,b:b,0),match($e$1,b:b,0)>match(b1,b:b,0)),iferror(offset(indirect(char(column()+64)&row()),-1,0)+1,1),""),"") 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -