Searching a multidemensional array...
-
I am working on a customized Excel VBA function. I have developed a two dimensional array consisting of two fields. The first element is a Date field and the second field is an Integer field. The problem is that now I need to search through the array using the first field, and when a match is found to return the second field as the result. The name of the array is arrArray. It is a static array with a set number of records. How should I go about searching the array? As an example, let us assume that there are ten elements and that they are properly loaded like this:
Dim arrArray(10, 1) arrArray(#1/1/2006#, 1) arrArray(#1/2/2006#, 4)
How do I search through the first element field for a match, and when a match is found to return the second element? :confused::confused::confused:
-
I am working on a customized Excel VBA function. I have developed a two dimensional array consisting of two fields. The first element is a Date field and the second field is an Integer field. The problem is that now I need to search through the array using the first field, and when a match is found to return the second field as the result. The name of the array is arrArray. It is a static array with a set number of records. How should I go about searching the array? As an example, let us assume that there are ten elements and that they are properly loaded like this:
Dim arrArray(10, 1) arrArray(#1/1/2006#, 1) arrArray(#1/2/2006#, 4)
How do I search through the first element field for a match, and when a match is found to return the second element? :confused::confused::confused:
Assuming you have filled the array with something like:
arrArray(1, 0) = "#1/1/2006#"
arrArray(1, 1) = 1
arrArray(2, 0) = "#1/2/2006#"
arrArray(2, 1) = 4Then something like this should do it
Dim retVal
Dim match
Dim imatch = "#1/2/2006#"
For i = 1 To 10
If arrArray(i, 0) = match Then
retVal = arrArray(i, 1)
End If
Next iRegards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis