max & min of a:a ect........

jdavis9

Active Member
Joined
Mar 8, 2002
Messages
337
How do i return the max and min values of a column to vb?

the equiv of =max(a:a) or =min(a:a)

Thanks
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Mudface

MrExcel MVP
Joined
Feb 18, 2002
Messages
3,339
Try the following, change the MsgBox bit to YourVariable = ... etc: -
<pre>
MsgBox Application.WorksheetFunction.Max(Range("A:A"))
MsgBox Application.WorksheetFunction.Min(Range("A:A"))
</pre>
 

dk

MrExcel MVP
Joined
Feb 15, 2002
Messages
2,942
Hi,

You can use Excel's WorksheetFunction object to use many worksheet functions in your VBA code. For example:-

Code:
Sub GetMaxAndMinValues()
Dim vMax, vMin

vMax = WorksheetFunction.Max(Range("A:A"))
vMin = WorksheetFunction.Min(Range("B:B"))

MsgBox "Maximum value in column A = " & vMax & vbCrLf & _
        "Minimum value in column B = " & vMin, vbInformation, "Max and Min"

End Sub

To see a comprehensive list of worksheet functions which work in VBA see List Of Worksheet Functions Available to Visual Basic,
 

Forum statistics

Threads
1,144,330
Messages
5,723,749
Members
422,513
Latest member
Meathead2022

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top