Counting the distance between similar values by rows using excel-vba/udf -
i having trouble in counting distance between values similar because there’s no function in excel achieve , deal 2000 row of values. prefer excel-vba this, button perhaps generates distances in example. array formulas lags excel when there's many values. counting them 1 1 waste of time. please want have done. appreciate if genius out there pull off.
you try this
option explicit sub main() dim cell range, f range dim rowoffset long worksheets("gaps").range("a2:f10") '<--| change actual range of interest each cell in .specialcells(xlcelltypeconstants, xlnumbers) rowoffset = 1 set f = .find(what:=cell, after:=cell, lookin:=xlvalues, lookat:=xlwhole, searchdirection:=xlprevious) if not f nothing , f.row <= cell.row rowoffset = cell.row - f.row + 1 cell.offset(, .columns.count + 1) = rowoffset '<--| "+1" offset results range 1 column away values range: adjust per needs next cell end end sub
tested on "values" gives same "value row gaps" except cell "k4": hope it's miscount on part...
should ever need display output in same "relative" position on worksheet (say: "sheet2") change
cell.offset(, .columns.count + 1) = rowoffset
to
worksheets("sheet2").range(cell.offset(, .columns.count + 1).address) = rowoffset
Comments
Post a Comment