VBA: Search through array's

BIGTONE559

Active Member
Joined
Apr 20, 2011
Messages
336
Greetings,

i'm looking for help on a efficient way of searching multiple arrays for data. i've come up with the following starting point however. I'm kinda lost as to where i should begin.

All help is appreciated


Code:
Dim d as integer 'Date Counter
Dim c as integer 'Color Counter
dim i as integer 'item counter
dim L as integer 'location counter

Range("A1:A500").name="MyData"

Dim MyDates as variant
Dim MyColor as variant
Dim MyItem as variant
Dim MyLocation as variant

MyDates=Range("MyDates")
MyColor=Range("MyColor")
MyItem=Range("MyItem")
MyLocation=Range("MyLocation")


for d=1 to ubound(MyDates)
    for c=1 to ubound(MyColor)
           for i=1 to ubound(MyItem)
                    for L=1 to ubound(MyLocation)

' i would like to sort through a large data set to find values that meet the following criteria.


'if "date" and "color" and "item" and "location" matches then blah blah

                  next L
               next i
             next c
           next d
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Missing some info so I made a lot assumptions. Maybe more information as to what is being used in the search and the relationship of the different arrays.

Code:
Dim i As Integer 'item counter


Range("A1:A500").Name = "MyData"

Dim MyDates As Variant
Dim MyColor As Variant
Dim MyItem As Variant
Dim MyLocation As Variant

MyDates = Range("MyDates")
MyColor = Range("MyColor")
MyItem = Range("MyItem")
MyLocation = Range("MyLocation")



For i = 1 To UBound(MyDates)
    If MyDates(i) = SOMEDATE And MyColor(i) = SOMECOLOR _
        And MyItem(i) = SOMEITEM And MyLocation(i) = SOMELOCATION Then
        ''MATCH FOUND
    End If
Next i
 
Upvote 0
Missing some info so I made a lot assumptions. Maybe more information as to what is being used in the search and the relationship of the different arrays.

Code:
Dim i As Integer 'item counter


Range("A1:A500").Name = "MyData"

Dim MyDates As Variant
Dim MyColor As Variant
Dim MyItem As Variant
Dim MyLocation As Variant

MyDates = Range("MyDates")
MyColor = Range("MyColor")
MyItem = Range("MyItem")
MyLocation = Range("MyLocation")



For i = 1 To UBound(MyDates)
    If MyDates(i) = SOMEDATE And MyColor(i) = SOMECOLOR _
        And MyItem(i) = SOMEITEM And MyLocation(i) = SOMELOCATION Then
        ''MATCH FOUND
    End If
Next i


How will i handle the other arrays? those are dynamic arrays that will need to be incremented as well.
 
Upvote 0

Forum statistics

Threads
1,207,421
Messages
6,078,436
Members
446,337
Latest member
nrijkers

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top