arrays

  • Thread starter Thread starter Dave B
  • Start date Start date
D

Dave B

Hi,

I want to work with an array which contains state names (e.g. Dim
strStateNames(49) as String). Is there an easy way to fill the array
without getting the data somewhere else? For instance:

strStateNames(1 To 50) = "Alabama", "Alaska", "Arizona", "Arkansas", etc.

instead of:

strStateNames(0) = "Alabama"
strStateNames(1) = "Alaska"
strStateNames(2) = "Arizona"
etc. (ugh!)

I know I can put the names in a worksheet and then:

For i = 0 To 49
strStateNames(i) = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
Next i

But is there an easy way to do this without going somewhere else for the
data? Thanks.

Dave
 
Dim strSplit() as String
Dim strStates as String: states = "Alabama,Alaska,Arizona,Arkansas,etc"

strSplit = Split(strStates, Chr(44), -1, vbBinaryCompare)


Tim Riley
 
Another way:

dim strStateNames as Variant
strStateNames = array("alabama", "alaska", "West Virginia")

or even:

Dim strStateNames As Variant
strStateNames _
= Application.Transpose(Worksheets("sheet1").Range("a1:a50").Value)

But the bottom one is a base 1 array (1 to 50)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top