Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy question M&M[_2_] Excel Discussion (Misc queries) 3 August 11th 07 07:00 AM
Easy Question M&M[_2_] Excel Discussion (Misc queries) 3 July 24th 07 12:34 AM
Easy Question Bob[_8_] Excel Worksheet Functions 9 July 14th 07 03:50 PM
new user with easy question? not easy for me speakeztruth New Users to Excel 5 June 3rd 05 09:40 PM
Probably the most easy question here... JasonS[_2_] Excel Programming 1 October 8th 04 12:08 AM


All times are GMT +1. The time now is 06:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"