Wrox Programmer Forums
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 2nd, 2005, 11:50 AM
Authorized User
Join Date: Sep 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default arrays

Hi again,

could someone help me out with an array in vba?

I have about 15 words that I want to search for in an excel spreadsheet.

for each word in the array, i want to search the sheet for it, and if it finds it, add 1 to a counter. when the sheet has searched for that word, i want to assign the number to a variable, reset the number to 0, and start counting the next word.

arrays baffle me at the best of times, and as i still don't know too much about vba arrays, if someone could help me tht would be great. just about to google it, but would still appreciate any help that is on offer.



Visit my site: http://www.drybonesuk.com
Visit my site: http://www.drybonesuk.com
Old November 3rd, 2005, 02:11 AM
Friend of Wrox
Join Date: Nov 2003
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.

Old November 4th, 2005, 06:11 AM
Authorized User
Join Date: Sep 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts

thats fine thanks. used that as a base and played around a bit and have it working fine now. my code is not very dynamic, but hey, at least it does the job for now. :o)


Visit my site: Dry Bones Internet Solutions

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help With Arrays Crippy Ruby 2 March 6th, 2013 05:59 PM
Multidemmesional Arrays OR arrays gmoney060 Classic ASP Basics 3 November 1st, 2004 03:42 PM
Arrays tajin Excel VBA 0 June 20th, 2004 09:07 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.