Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default 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" wrote in message
. com...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default 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(strXls File).Worksheets(i).Range(
strRange))


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default 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(strXls File).Worksheets(i).Range(
strRange))



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Last cell in Range when range is date format default105 Excel Discussion (Misc queries) 5 July 7th 09 03:11 PM
Find the MAX number in range, then find... pgarcia Excel Discussion (Misc queries) 4 September 19th 08 06:58 PM
Find a range of values in a range of cells Jack Taylor Excel Worksheet Functions 20 November 25th 06 01:26 PM
Find dates in a range; then sum values in that range by a criteria Anders Excel Discussion (Misc queries) 4 October 21st 05 03:41 PM
Find first cell in range and expand range -VBA Caméléon Excel Programming 3 December 4th 04 02:01 AM


All times are GMT +1. The time now is 05:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"