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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

BobUmlas

Well-known Member
Joined
Mar 14, 2002
Messages
1,181
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
 

Zack Barresse

MrExcel MVP
Joined
Dec 9, 2003
Messages
10,881
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
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?
 

kmh6278

Board Regular
Joined
Mar 7, 2006
Messages
52
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,307
Messages
5,641,436
Members
417,209
Latest member
Agbarker

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
Top