Nice code Dennis. :wink:
Also, as a tack-on, as we're not approaching Excel's 5461 element limitation (removed in XP
), we can also use the Excel Object's min and max functions to get at the min and max values. Here's a few examples:
<font face=Courier New><SPAN style="color:darkblue">Option</SPAN> <SPAN style="color:darkblue">Explicit</SPAN>
<SPAN style="color:darkblue">Sub</SPAN> Mn_MX_Value()
<SPAN style="color:darkblue">Dim</SPAN> vaData, LnMax <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, lnMin <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, tmpAr() <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>, MyDim <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> i <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>
vaData = ThisWorkbook.Sheets(1).[A1:c10].Value
<SPAN style="color:darkblue">ReDim</SPAN> tmpAr(1 <SPAN style="color:darkblue">To</SPAN> <SPAN style="color:darkblue">UBound</SPAN>(vaData))
MyDim = 1 <SPAN style="color:green"><SPAN style="color:green">'Desired Dimension, 1 to 3</SPAN></SPAN>
<SPAN style="color:darkblue">For</SPAN> i = 1 <SPAN style="color:darkblue">To</SPAN> <SPAN style="color:darkblue">UBound</SPAN>(vaData)
tmpAr(i) = vaData(i, MyDim)
<SPAN style="color:darkblue">Next</SPAN>
lnMin = Application.Min(tmpAr)
LnMax = Application.Max(tmpAr)
MsgBox lnMin & " " & LnMax
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN>
<SPAN style="color:darkblue">Sub</SPAN> test()
<SPAN style="color:darkblue">Dim</SPAN> MyArray(0 <SPAN style="color:darkblue">To</SPAN> 3, 0 <SPAN style="color:darkblue">To</SPAN> 119) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>, i <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> lnMin <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, LnMax <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Long</SPAN>, tmp(0 <SPAN style="color:darkblue">To</SPAN> 119) <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>, MyDim <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Integer</SPAN>
<SPAN style="color:darkblue">For</SPAN> i = 0 <SPAN style="color:darkblue">To</SPAN> 119
MyArray(0, i) = i - 2: MyArray(1, i) = i * 2 + 5
MyArray(2, i) = i * 3 + 1: MyArray(3, i) = i * 4 - 3
<SPAN style="color:darkblue">Next</SPAN>
MyDim = 0 <SPAN style="color:green"><SPAN style="color:green">'Desired Dimension, 0 to 3</SPAN></SPAN>
<SPAN style="color:darkblue">For</SPAN> i = 0 <SPAN style="color:darkblue">To</SPAN> 119
tmp(i) = MyArray(MyDim, i)
<SPAN style="color:darkblue">Next</SPAN>
lnMin = Application.Min(tmp)
LnMax = Application.Max(tmp)
MsgBox lnMin & " " & LnMax
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>
Have nice day.