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.
to
so need too
- loop thrugh column b
- scell = find cell in
- samples = count cells in between s , inspector
- startcell = scell + 1
- 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:
- this work numbers , text
- this not work blanks
- 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
Post a Comment