Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default MIN IF Function

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default MIN IF Function

On Jan 28, 1:58 pm, Aaron wrote:
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


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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default MIN IF Function

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?

"SteveM" wrote:

On Jan 28, 1:58 pm, Aaron wrote:
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


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

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
User Function Question: Collect Condition in Dialog Box - But How toInsert into Function Equation? SteveM Excel Programming 1 January 3rd 08 03:45 PM
copy of excel file not showing formulal/function in the function b oaallam Excel Discussion (Misc queries) 4 September 6th 07 01:20 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Excel - User Defined Function Error: This function takes no argume BruceInCalgary Excel Programming 3 August 23rd 06 08:53 PM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


All times are GMT +1. The time now is 01:31 PM.

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

About Us

"It's about Microsoft Excel"