View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Need help with a easy programming question


My interpretation...
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

Function MaxVal(ByRef DataArray() As Double, _
ByRef TheOtherArray() As Double) As Double
Dim NumRows As Long
Dim NumCols As Long
Dim i As Long
Dim j As Long
Dim x As Long
Dim y As Long

MaxVal = DataArray(1, 1)
NumRows = UBound(DataArray)
NumCols = UBound(DataArray, 2)
For i = 1 To NumRows
For j = 1 To NumCols
If DataArray(i, j) MaxVal Then
x = i
y = j
End If
Next j
Next i
MaxVal = TheOtherArray(x, y)
End Function
'----
Sub NewsgroupTestForMaxVal()
'Create two arrays and call the MaxVal function.
Dim arrFirst() As Double
Dim arrSecond() As Double
Dim lngN As Long
Dim x As Double

ReDim arrFirst(1 To 4, 1 To 5)
ReDim arrSecond(1 To 4, 1 To 5)

'Load the arrays
For lngN = 1 To 4
For x = 1 To 5
arrFirst(lngN, x) = lngN + x * 2
arrSecond(lngN, x) = lngN + x * 3
Next
Next
'For reference purposes, to check the result returned.
'Range("A1:E4").Value = arrFirst()
'Range("G1:K4").Value = arrSecond()

'Call the function
x = MaxVal(arrFirst, arrSecond)
MsgBox x
End Sub
'-------------



"NickCo7" wrote in message
My maximum value looks like this.

Option Explicit
Option Base 1
Function MaxVal(DataArray)
Dim NumRows As Integer, NumCols As Integer
Dim i As Integer, j As Integer
MaxVal = DataArray(1, 1)
NumRows = DataArray.Rows.Count
NumCols = DataArray.Columns.Count
For i = 1 To NumRows
For j = 1 To NumCols
If DataArray(i, j) MaxVal Then
MaxVal = DataArray(i, j)
End If
Next j
Next i
End Function