search - Excel: Find value in column(s) -
i've got excel spreadsheet multiple columns of different lengths, each filled unsorted numbers. each column has header.
is there way determine column(s) contain number?
for instance, i'd love able =whichcols( 123, a, z ) , have excel tell me columns [b, c, , k] contain cells value of 123. though, ideally, i'm after comma separated list of headers.
equally adequate find cells, in range (or ranges), have value; e.g. [b19, c32, , k908].
i feel i'm overlooking obvious built-in function.
there might built-in way can write own function.
put code in vba module
:
public function whichcols(searchvalue double, srcrange range) string dim rangecolumn range dim columncell range dim headerrow long headerrow = 1 ' headerinformation in rownr 1 ' whichcols = vbnullstring each rangecolumn in srcrange.columns each columncell in rangecolumn.cells if columncell = searchvalue if whichcols <> vbnullstring whichcols = whichcols & ", " whichcols = whichcols & srcrange.parent.cells(headerrow, columncell.column) exit end if next columncell next rangecolumn end function
an example call in excel be:
=whichcols(7,a2:f3)
Comments
Post a Comment