Solved

Find Min & Max VBA

Posted on 2013-01-04
6
717 Views
Last Modified: 2013-01-05
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
Comment
Question by:Rayne
6 Comments
 

Author Comment

by:Rayne
Comment Utility
Also, all the numbers in that set, will be of same number of digits, just different

thanks
0
 
LVL 78

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 75 total points
Comment Utility
@min(range)
@max(range)
0
 
LVL 45

Assisted Solution

by:Martin Liss
Martin Liss earned 125 total points
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 17

Accepted Solution

by:
andrewssd3 earned 300 total points
Comment Utility
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
 

Author Closing Comment

by:Rayne
Comment Utility
Thanks everyone :) for your excellent help. I badly needed this

R
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2012
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now