+ Reply to Thread
Results 1 to 5 of 5

VBA - maximum and minimum extraction

Hybrid View

  1. #1
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    VBA - maximum and minimum extraction

    I'd like to have a macro that looks at 2 or 3 cells in a spreadsheet and simply extracts their max or min, with the least amount of code such as this:

    max_value = Maximum(Worksheets("Sheet1").Range("D49").Value, Worksheets("Sheet1").Range("D55").Value)
    How can this be done?

    Thanks

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    simple maximum and minimum extraction

    Not sure exactly what you're looking for.

    Here's something to play with:
    Sub GetMaxVal()
        Dim max_value
        max_value = WorksheetFunction.Max([Sheet1].Range("D49", "D55"))
        MsgBox max_value
    End Sub
    Can you work with that?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679
    yes - exactly what I need. Thank you

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    max_value = WorksheetFunction.Max([Sheet1].Range("D49", "D55"))
    .. is equivalent to
    max_value = WorksheetFunction.Max([Sheet1].Range("D49:D55"))
    I think Ron meant
    max_value = WorksheetFunction.Max([Sheet1].Range("D49, D55"))

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    VBA - maximum and minimum extraction

    Shg, thanks so much for catching that error!
    I'd only tested it on a blank sheet with values in those two cells.
    Didn't even notice the code referenced the entire range.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1