Solved

Find Min & Max VBA

Posted on 2013-01-04
6
734 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Author Comment

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

thanks
0
 
LVL 80

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 75 total points
ID: 38746329
@min(range)
@max(range)
0
 
LVL 47

Assisted Solution

by:Martin Liss
Martin Liss earned 125 total points
ID: 38746639
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 17

Accepted Solution

by:
andrewssd3 earned 300 total points
ID: 38746684
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
ID: 38747100
Thanks everyone :) for your excellent help. I badly needed this

R
0
 
LVL 47

Expert Comment

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

Marty - MVP 2009 to 2012
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help to break down spreadsheet 3 42
Tricky Shapes formula 3 18
Macro to open folder and copy data from all excel files 10 21
Excel Formula 6 25
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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