ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to select MIN MAX from selection (https://www.excelbanter.com/excel-programming/399585-macro-select-min-max-selection.html)

[email protected]

Macro to select MIN MAX from selection
 
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


JW[_2_]

Macro to select MIN MAX from selection
 
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

wrote:
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



[email protected]

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

On Oct 18, 11:28 am, JW wrote:
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

wrote:
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




JW[_2_]

Macro to select MIN MAX from selection
 
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)

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

On Oct 18, 11:28 am, JW wrote:
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

wrote:
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




All times are GMT +1. The time now is 12:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com