Creating an Array from Cell Contents

kmh6278

Board Regular
Joined
Mar 7, 2006
Messages
52
I have data in column A of a spreadsheet. I'd like to create an array that contains all of that data, so that I can loop through it in VBA.

If the contents of A1, A2 and A3 are "example1"," example2", and "example3", in the end, I would like word_list to be something like:

word_list=array("example1","example2", "example3")

Here is what I have been working with, but it doesn't seem to be returning what I had anticipated it would

Dim DataList As Range, word_list As Variant


Set DataList = Sheets("Sheet2").Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
word_list = DataList.Value
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Sub Demo()
wordlist = Range("A1:A3") '<==yes, as easy as that.
For i = 1 To 3
Debug.Print wordlist(i, 1) '<===just to prove it!:)
Next
End Sub
 
Upvote 0
You don't need to create a range array, which I would suggest highly against doing. You can loop through the range as desired, as-is. Can you define your problem a little more, so we may help with the VBA you're looking for? For example, what is "DataList"? Where is this code located? Is it a userform, or a control on the worksheet?
 
Upvote 0
Thanks for the responses. The plan is to have a list of key words maintained in Excel, which will then be looped through using a macro, searched and replaced in Word documents for editing files. I'd like to prevent having colleagues edit code by having them make any necessary changes to the Excel worksheet and not through the VBA editor.
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,726
Members
448,987
Latest member
marion_davis

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