Thread: arrays
View Single Post
Old November 3rd, 2005, 02:11 AM
acdsky acdsky is offline
Friend of Wrox
Join Date: Nov 2003
Location: Johannesburg, , South Africa.
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky


Arrays are pretty straight forward. You could do something like this:

Dim MyArr as Variant
'if you want to load 2 values into the array e.g "A" and "B"
ReDim MyArr(0,1) 'Here you tell the array that you will have one object/row of data (The 0) which will contain 2 values


To Set the data in the array:

MyArr(0,0) = "A"
MyArr(0,1) = "B"

To Retrieve the values:

ValueA = MyArr(0,0)
ValueB = MyArr(0,1)

If you do multiples rows of data declare the Array as:

Redim MyArr(1,1)

Now you can load (0,0) and (0,1) and also a second row/set of data into (1,0) and (1,1) the rest is similar.

So in your case your code will look something like this:

Dim MyArr as Variant
ReDim MyArr(0,14)

MyArr(0,0) = "Word1"
MyArr(0,1) = "Word2"

etc etc...
'Now loop through the array, get the word, do the search and increment your counter.
n = 0 'n is the counter
For i = 0 To 14
 MySearchText = MyArr(0,i)
    '***Do excel Search logic. Assuming you loop through all the cells
        ' ""If MySearchText in Found then""
           n = n + 1
         '"""End the if""
    n = 0

Hope this helps...lemme know if you need more info.