Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 766
  • Last Modified:

Find Min & Max VBA

Hello,

I have a set of numbers in column B like below:
43
432342
432
342
34234324
534
432
3
443
543
432
4453
34
323243


I need the best way via VBA to find the Maximum and minimum of this set? How to do it?

Thanks
0
Rayne
Asked:
Rayne
3 Solutions
 
RayneAuthor Commented:
Also, all the numbers in that set, will be of same number of digits, just different

thanks
0
 
David Johnson, CD, MVPOwnerCommented:
@min(range)
@max(range)
0
 
Martin LissRetired ProgrammerCommented:
ve3ofa meant =min and =max so for example if the data is in column A starting in A1

=MIN(A1:A12)
=MAX(A1:A12)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
andrewssd3Commented:
The question was asking about VBA, so this illustrates a couple of ways of doing it with VBA:
Public Sub MaxInCol()

    Dim dMaxVal As Double
    
    
    ' simple version if you just want the whole column
    dMaxVal = Application.WorksheetFunction.Max(Range("B:B"))


    ' more complicated to limit to certain data
    Dim rngDataStart As Range
    Dim rngDataEnd As Range
    
    Set rngDataStart = Range("B2")
    ' find  the last cell with data in col B
    Set rngDataEnd = Cells(ActiveSheet.Rows.Count, 2).End(xlUp)

    dMaxVal = Application.WorksheetFunction.Max(Range(rngDataStart, rngDataEnd))
    
    Stop

End Sub

Open in new window

Obviously for min just use Application.WorksheetFunction.Min
0
 
RayneAuthor Commented:
Thanks everyone :) for your excellent help. I badly needed this

R
0
 
Martin LissRetired ProgrammerCommented:
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2012
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now