String array initialisation

M

major_yash

Hi,


I am facing a problem in intialising a string array in VBA. I need to
intialise an array of 10 elements from data in a range. This range has
text values. I tried to use following.


Code:
Dim VarNames() As String
.....
VarNames = ActiveSheet.Range("K22:K32").Value
.....

But I am getting Type Mismatch error. I don't want to use any loop to
populate the array. Filling each value is cumbersome.

Can anybody please suggest some way around.

Thanks,

Mhr
 
P

Piotr Lipski

Dnia 29 Jun 2006 12:21:48 -0700, (e-mail address removed) napisa³(a):
Dim VarNames

dim r as excel.range, strtmp as string
for each r in range("k22:k32").cells 'btw, that's 11 cells, not 10
strtmp = strtmp & switch(strtmp="", "", true, ";")
next r
VarNames = split(strtmp, ";")

There is probably someting better, but I always use this.
 

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

Top