Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

MIN IF Function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Aaron - 28 Jan 2008 18:58 GMT
I am looking for a function that is a lot like SUMIF function but is Min if.
Returns the min in a range by criteria.
Range, Criteria, and Min range
Any help would be great. Example below
Thanks in advance!

PN    |QTY| Min (Needed)
123  |  4   | 2
123  |  5   | 2
123  |  6   | 2
568  |  8   | 8
568  |  9   | 8
238  |  5   | 5
238  |  6   | 5
123  | 2    | 2

Aaron
SteveM - 28 Jan 2008 19:38 GMT
> I am looking for a function that is a lot like SUMIF function but is Min if.
> Returns the min in a range by criteria.
[quoted text clipped - 13 lines]
>
>  Aaron

Here's a crude one from my Personal Workbook that I coded up.  You can
try it and/or improve it:

SteveM

Public Function MinIf(Ref_Range As Range, Criterion As Variant,
Min_Range As Range) As Single
       Dim cell As Range
       Dim minVal As Single
       Dim iRow As Integer, jCol As Integer, iCount As Integer,
jCount As Integer

       iCount = Ref_Range.Rows.Count
       jCount = Ref_Range.Columns.Count

       minVal = Application.WorksheetFunction.Max(Min_Range)

       For iRow = 1 To iCount
           For jCol = 1 To jCount
               If Ref_Range.Cells(iRow, jCol).Value = Criterion Then
                   If Min_Range.Cells(iRow, jCol).Value < minVal Then
                       minVal = Min_Range.Cells(iRow, jCol).Value
                   End If
               End If
           Next
       Next

       MinIf = minVal

End Function
Aaron - 28 Jan 2008 19:53 GMT
Hi Steve,

I used the below function and got a #value error.
=PERSONAL.XLS!MinIf(A:A,A2,B:B) is what was used on the below example.
Am I doing something wrong?

> > I am looking for a function that is a lot like SUMIF function but is Min if.
> > Returns the min in a range by criteria.
[quoted text clipped - 44 lines]
>
> End Function
Aaron - 31 Jan 2008 14:58 GMT
Hi Steve,  

This works when I use a range and not the whole Column (A:A)
Thanks so much!

> > I am looking for a function that is a lot like SUMIF function but is Min if.
> > Returns the min in a range by criteria.
[quoted text clipped - 44 lines]
>
> End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.