I have something like
sdMax = WorksheetFunction.Max(Range("D2", Cells(emptyRow, 4)))
to find the maximum number of column D
How do I find the location of this maximum number?
For example: =ADDRESS(1,1) - returns the address of the first cell (i.e. the cell at the intersection of the first row and first column) as an absolute cell reference $A$1. =ADDRESS(1,1,4) - returns the address of the first cell as a relative cell reference A1.
1. To get the address of the cell with smallest value of this column, please apply this formula: =CELL("address",INDEX(A2:A15,MATCH(MIN(A2:A15),A2:A15,0))). 2. In above formula A2:A15 is the column cells that you want to use, you can change it to your need.
Max function is used to find the maximum value out of a range of values. It is an inbuilt function in Excel and categorized as the Max function. However, in VBA, there is no inbuilt function as Max to get the maximum value. Max function can be used in VBA Excel also.
Defined as a user defined function in vba, returning the address as a string
Function AddressOfMax(rng As Range) As String
AddressOfMax = WorksheetFunction.Index(rng, WorksheetFunction.Match(WorksheetFunction.Max(rng), rng, 0)).Address
End Function
Or returning a range reference
Function AddressOfMax(rng As Range) As Range
Set AddressOfMax = rng.Cells(WorksheetFunction.Match(WorksheetFunction.Max(rng), rng, 0))
End Function
these functions assume rng is one column wide
These functions can be used in the sheet
eg
=AddressOfMax(C:C)
or in vba
eg
Dim r As Range
Set r = AddressOfMax(Range("D2", Cells(emptyRow, 4)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With