+ Reply to Thread
Results 1 to 4 of 4

Find Min value in range with VBA?

  1. #1
    deko
    Guest

    Find Min value in range with VBA?

    I know this is pretty basic, but it's been a long night...

    How do I find the minimum value in a range?

    If I have Q2:Q12, and want to find the minimum value - via automation from
    Access, would it look something like this:

    dblMin = xlapp.Evaluate("MIN(Q2:Q12)") ??? same for Max ??

    Thanks in advance.



  2. #2
    Bernie Deitrick
    Guest

    Re: Find Min value in range with VBA?

    deko,

    This works:

    Dim dblMin As Double
    Dim xlApp As Object
    Dim xlBook As Excel.Workbook
    Dim xlSht As Excel.Worksheet

    Set xlApp = CreateObject("excel.application")
    Set xlBook = xlApp.Workbooks.Open("C:\Path\Filename.xls")
    Set xlSht = xlBook.ActiveSheet

    dblMin = xlApp.WorksheetFunction.Min(xlSht.Range("Q2:Q12"))
    MsgBox dblMin

    This requires a reference to your Excel application through Tools /
    References (in the VBE).

    HTH,
    Bernie
    MS Excel MVP


    "deko" <[email protected]> wrote in message
    news:[email protected]...
    > I know this is pretty basic, but it's been a long night...
    >
    > How do I find the minimum value in a range?
    >
    > If I have Q2:Q12, and want to find the minimum value - via automation from
    > Access, would it look something like this:
    >
    > dblMin = xlapp.Evaluate("MIN(Q2:Q12)") ??? same for Max ??
    >
    > Thanks in advance.
    >
    >




  3. #3
    deko
    Guest

    Re: Find Min value in range with VBA?

    > This works:
    >
    > Dim dblMin As Double
    > Dim xlApp As Object
    > Dim xlBook As Excel.Workbook
    > Dim xlSht As Excel.Worksheet
    >
    > Set xlApp = CreateObject("excel.application")
    > Set xlBook = xlApp.Workbooks.Open("C:\Path\Filename.xls")
    > Set xlSht = xlBook.ActiveSheet
    >
    > dblMin = xlApp.WorksheetFunction.Min(xlSht.Range("Q2:Q12"))
    > MsgBox dblMin
    >
    > This requires a reference to your Excel application through Tools /
    > References (in the VBE).


    Thanks! That really helped. Here's what seems to be working for me (still
    testing)...

    dblMin =
    xlapp.WorksheetFunction.Min(xlapp.Workbooks(strXlsFile).Worksheets(i).Range(
    strRange))



  4. #4
    Bernie Deitrick
    Guest

    Re: Find Min value in range with VBA?

    That should more than seem to work - I just didn't know how you were
    referencing the workbook and worksheet objects.

    HTH,
    Bernie
    MS Excel MVP

    > Thanks! That really helped. Here's what seems to be working for me

    (still
    > testing)...
    >
    > dblMin =
    >

    xlapp.WorksheetFunction.Min(xlapp.Workbooks(strXlsFile).Worksheets(i).Range(
    > strRange))




+ 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