ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need help with a easy programming question (https://www.excelbanter.com/excel-programming/358554-need-help-easy-programming-question.html)

NickCo7

Need help with a easy programming question
 

So I have to seperate arrays. I have a program written that will find
the maximum value from one of the arrays. I need to have the program
output a value from the second array that corresponds to the location
of the max value from the first array. What should I use to correspond
the two arrays in the end?


--
NickCo7
------------------------------------------------------------------------
NickCo7's Profile: http://www.excelforum.com/member.php...o&userid=33341
View this thread: http://www.excelforum.com/showthread...hreadid=531733


NickCo7[_2_]

Need help with a easy programming question
 

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


--
NickCo7
------------------------------------------------------------------------
NickCo7's Profile: http://www.excelforum.com/member.php...o&userid=33341
View this thread: http://www.excelforum.com/showthread...hreadid=531733


Jim Cone

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



All times are GMT +1. The time now is 05:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com