Fastest VBA MIN code

Silverjman

Board Regular
Joined
Mar 19, 2014
Messages
110
Hello,

I have a grid that is 4814 rows by 40 columns and need to do a simple NON Worksheetfunction MIN function.

From my googling this seems to be the best solution but I can't get the code to work.

VBA Code:
Function Min(ParamArray values() As Variant) As Variant
   Dim minValue, Value As Variant
   minValue = values(0)
   For Each Value In values
       If Value < minValue Then minValue = Value
   Next
   Min = minValue
End Function

Any idea whay I'm getting a Type 13 mismatch with this?
If I move the "minValue = Value" down to the next line I get a "Next without For" error?
Any help much appreciated
 
Last edited by a moderator:

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Do you have any text values or errors in the range of values you're using?
 
Upvote 0
Just highlighted the ranges and did Go To Special on both Text and Errors and none of either were found. Thanks for the suggestion, may help in the future.
 
Upvote 0
How are you calling the function?
 
Upvote 0
Else: Max_Recovery_result = Min(arr

VBA Code:
  If arrResolution__SubPortfolio(i, 1) = "REO" Then
             Max_Recovery_result = arrResolution__Total_Owned_Lien_Value_Grid(i, j)
             Else: Max_Recovery_result = Min(arrResolution__Total_Owned_Lien_Value_Grid(i, j), arrResolution__Loan_Balance)
             End If
 
Upvote 0
Is "arrResolution__Loan_Balance" an array of values?
 
Upvote 0
Ugg THANK YOU. I feel silly now.
Min(arrResolution__Total_Owned_Lien_Value_Grid(i, j), arrResolution__Loan_Balance(i, j))

Definitive novice, that's a good lesson that the function or line the debug highlights very well may not be the issue!
That was a tremendous help! Thanks again
 
Upvote 0
You're welcome & thanks for the feedback.
Although I don't see the need for the function, when you are only sending 2 values
 
Upvote 0
Ahh, yeah maybe I was a bit blinded by just trying to convert a formula that used MIN to VBA.

Are you saying you would use something like the below instead of a MIN?

If Lien > Loan Then
Lien
Else Loan
 
Upvote 0
Something like that yes.
 
Upvote 0

Forum statistics

Threads
1,215,005
Messages
6,122,661
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top