Macro to select MIN MAX from selection

U

ucanalways

If the user hits the command button, what would be the macro to find
the minimum and maximum of the users selection.

In excel front end, it is done by using = min( ) and =max( )

Can the code be tweaked to ignore any alphabets/words from the
selection and find the min and max for the only the numbers in the
selection?

I would appreciate anyone willing to assist me in this.

Marvin
 
J

JW

Sub getMinMax()
Dim minValue As Double
Dim maxValue As Double
maxValue = WorksheetFunction.Max(Selection)
minValue = WorksheetFunction.Min(Selection)
MsgBox "minimum value: " & minValue & Chr(10) & _
"maximum value: " & maxValue
End Sub
 
U

ucanalways

Jeff, Thanks. Is there any way to ignore the #DIV/0! in the selection
and return the min and max of the selection?
 
J

JW

I would STRONGLY urge that you handle the DIV/0 error in your
formula. You can do this using IsErr, IsError, or an Or statement.
=IF(OR(A2=0,B2=0),0,A2/B2)
=IF(ISERR(A2/B2),0,A2/B2)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top