0

I'm trying to create multiple arrays containing our companies departments in vba. I have basic coding skills but cant seem to get the syntax down right. This is essentially what i am trying to do. Ill post the methods i have tried.

Dim Bitman(2) As String
Bitman(0) = "Charlotte"
Bitman(1) = "Raleigh"
Bitman(2) = "Wilmington"

and

Dim Bitman("Charlotte", "Raleigh", "Wilmington")

I have also tried looking up the solution on here but nothing has helped. This seems very basic and easy and i know i have the logic down, i just need to know how to tell the computer.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ken Feier
  • 25
  • 6

2 Answers2

1

You can also do this:

'comma-separated list of {whatever you want to put in the array}
Const myList as String = "Charlotte,Raleigh,Wilmington"

Sub foo()

Dim Bitman() As String
Bitman = Split(myList, ",")

MsgBox Bitman(1) 'etc.

End Sub

I like this method, since it provides a simple place for maintaining the list, and you don't need to declare the bounds of the array, either. I often use this method because arrays can't be declared outside of a procedure.

David Zemens
  • 53,033
  • 11
  • 81
  • 130
-1

Another thing you can do is if you write the names of the department on your worksheets, lets say you have "Charlotte" in A1, "Raliegh" in A2, and "Wilmington" in A3, you can create a range array and then put those objects in it very easily. The code would be as follows.

Dim Bitman as Range
Set Bitman = Range("A1:A3")

If you do that then Bitman(0) = Charlotte, Bitman(1) = Raliegh, and Bitman(2) = Wilmington

FairlyLegit
  • 233
  • 1
  • 10
  • The OP does not necessarily use Excel. Even if they do, your code [will fail](http://stackoverflow.com/a/17877644/11683) with "Object variable of With block variable not set." – GSerg Apr 24 '15 at 19:04
  • I did not notice that excel was not mentioned, also I am incompetent. I am going to go sulk now. – FairlyLegit Apr 24 '15 at 19:12