Index of Minimum Value in Array

afzalw

New Member
Joined
Jul 24, 2012
Messages
20
I have two Array Input(k) and Output(k).

I am looking to print Input(k) value for the corresponding minimum Output(k). This code is giving p = 1 but my minimum value is not at the index one in the array.
Code:
p = Application.Match(Application.Min(Output), Output, 0)
Debug.Print p

Set rDest = ThisWorkbook.Sheets("Design2").Cells(j, 16)                                  
rDest.Resize(1, 1).Value = Input(p)
 
This worked for me:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG22Mar36
[COLOR="Navy"]Dim[/COLOR] nOutput [COLOR="Navy"]As[/COLOR] Variant, nInput [COLOR="Navy"]As[/COLOR] Variant, P [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
nOutput = Range("A1:A10")
nInput = Range("B1:B10")
  P = Application.Match(Application.Min(nOutput), nOutput, 0)
  Debug.Print P
  MsgBox nInput(P, 1)
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]

[TABLE="width: 116"]
<colgroup><col width="27" style="width: 20pt; mso-width-source: userset; mso-width-alt: 967;"> <col width="64" style="width: 48pt;" span="2"> <tbody>[TR]
[TD="class: xl63, width: 27, bgcolor: #DAEEF3"] [/TD]
[TD="class: xl63, width: 64, bgcolor: #DAEEF3"]A[/TD]
[TD="class: xl63, width: 64, bgcolor: #DAEEF3"]B[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: #DAEEF3, align: right"]1[/TD]
[TD="class: xl64, bgcolor: #DCE6F1, align: right"]10[/TD]
[TD="class: xl64, bgcolor: #DCE6F1, align: right"]100[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: #DAEEF3, align: right"]2[/TD]
[TD="class: xl65, bgcolor: white, align: right"]11[/TD]
[TD="class: xl65, bgcolor: white, align: right"]101[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: #DAEEF3, align: right"]3[/TD]
[TD="class: xl64, bgcolor: #DCE6F1, align: right"]12[/TD]
[TD="class: xl64, bgcolor: #DCE6F1, align: right"]102[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: #DAEEF3, align: right"]4[/TD]
[TD="class: xl65, bgcolor: white, align: right"]13[/TD]
[TD="class: xl65, bgcolor: white, align: right"]103[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: #DAEEF3, align: right"]5[/TD]
[TD="class: xl64, bgcolor: #DCE6F1, align: right"]2[/TD]
[TD="class: xl64, bgcolor: #DCE6F1, align: right"]104[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: #DAEEF3, align: right"]6[/TD]
[TD="class: xl65, bgcolor: white, align: right"]15[/TD]
[TD="class: xl65, bgcolor: white, align: right"]105[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: #DAEEF3, align: right"]7[/TD]
[TD="class: xl64, bgcolor: #DCE6F1, align: right"]16[/TD]
[TD="class: xl64, bgcolor: #DCE6F1, align: right"]106[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: #DAEEF3, align: right"]8[/TD]
[TD="class: xl65, bgcolor: white, align: right"]17[/TD]
[TD="class: xl65, bgcolor: white, align: right"]107[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: #DAEEF3, align: right"]9[/TD]
[TD="class: xl64, bgcolor: #DCE6F1, align: right"]18[/TD]
[TD="class: xl64, bgcolor: #DCE6F1, align: right"]108[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: #DAEEF3, align: right"]10[/TD]
[TD="class: xl65, bgcolor: white, align: right"]19[/TD]
[TD="class: xl65, bgcolor: white, align: right"]109[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: #DAEEF3, align: right"]11[/TD]
[TD="class: xl64, bgcolor: #DCE6F1, align: right"]20[/TD]
[TD="class: xl64, bgcolor: #DCE6F1, align: right"]110[/TD]
[/TR]
</tbody>[/TABLE]



Regards Mick
 
Upvote 0

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