Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 2nd, 2005, 11:50 AM
Authorized User
Join Date: Sep 2003
Location: , , United Kingdom.
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
Reply With Quote
  #2 (permalink)  
Old November 3rd, 2005, 02:11 AM
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.

Reply With Quote
  #3 (permalink)  
Old November 4th, 2005, 06:11 AM
Authorized User
Join Date: Sep 2003
Location: , , United Kingdom.
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
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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

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

All times are GMT -4. The time now is 08:09 AM.

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