excel - VBA Cell address of Max() -


i have like

sdmax = worksheetfunction.max(range("d2", cells(emptyrow, 4))) 

to find maximum number of column d

how find location of maximum number?

defined user defined function in vba, returning address string

function addressofmax(rng range) string     addressofmax = worksheetfunction.index(rng, worksheetfunction.match(worksheetfunction.max(rng), rng, 0)).address  end function 

or returning range reference

function addressofmax(rng range) range     set addressofmax = rng.cells(worksheetfunction.match(worksheetfunction.max(rng), rng, 0))  end function 

these functions assume rng 1 column wide

these functions can used in sheet
eg

=addressofmax(c:c) 

or in vba
eg

dim r range set r = addressofmax(range("d2", cells(emptyrow, 4))) 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -