I want to modify this sub procedure (Sub only) that looks for minimum temperature from 4 places (4 columns), into one with Function procedure.
Sub test()
Dim i As Integer, j As Integer
Dim temp(30, 3) As Integer
Dim minTemp(3) As Integer
Dim tmp As Integer
For i = 2 To 30
For j = 2 To 5
temp(i - 2, j - 2) = Cells(i, j).Value
Next j
Next i
For j = 0 To 3
minTemp(j) = 100
tmp = 0
For i = 0 To 30
tmp = temp(i, j)
If minTemp(j) >= tmp Then
minTemp(j) = tmp
End If
Next i
Cells(33, j + 2).Value = minTemp(j)
Next j
End Sub
and I try to modify into:
Sub test()
Dim i As Integer, j As Integer
Dim temp(30, 3) As Integer
For i = 2 To 30
For j = 2 To 5
temp(i - 2, j - 2) = Cells(i, j).Value
Next j
Next i
MsgBox LowestTemp(temp())
End Sub
Function LowestTemp(tArr() As Variant) As Variant
For i = LBound(tArr) To UBound(tArr)
minVal = tArr(1)
For j = 0 To 3
If tArr(j) >= minVal Then
minVal = tArr(j)
End If
Next i
LowestTemp = minVal
End Function
but I find it hard to pass the 2-D array to the Function procedure, please help?