Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Fill an Array with String values
Simple question. How do I load a list of strings into an array?
I know I code so the following but it seems inefficient. Dim a (1 to 20) as String a(1) = "String1" a(2) = "String2" etc... Can I do something like... a(1 to 20) = "String1", "String2", "String3" ....."String20" or a = Array("String1", "String2", "String3" ....."String20" ) Thanks. - John Michl www.JohnMichl.com |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Fill an Array with String values
John,
Dim a a = Array("String1", "String2", "String3" ....."String20" ) Don't pre-dimension it. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "John Michl" wrote in message ... Simple question. How do I load a list of strings into an array? I know I code so the following but it seems inefficient. Dim a (1 to 20) as String a(1) = "String1" a(2) = "String2" etc... Can I do something like... a(1 to 20) = "String1", "String2", "String3" ....."String20" or a = Array("String1", "String2", "String3" ....."String20" ) Thanks. - John Michl www.JohnMichl.com |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Fill an Array with String values
For 20 values, I am not sure the individual assignment approach is
particularly costly. Option Explicit Sub main() Dim v As Variant, i As Integer v = Split("abc,def,ghi,jkl", ",") Debug.Print "------------" For i = LBound(v) To UBound(v) Debug.Print v(i) Next Debug.Print "------------" v = Array("mno", "pqr", "stu", "vwx") For i = LBound(v) To UBound(v) Debug.Print v(i) Next End Sub "John Michl" wrote in message ... Simple question. How do I load a list of strings into an array? I know I code so the following but it seems inefficient. Dim a (1 to 20) as String a(1) = "String1" a(2) = "String2" etc... Can I do something like... a(1 to 20) = "String1", "String2", "String3" ....."String20" or a = Array("String1", "String2", "String3" ....."String20" ) Thanks. - John Michl www.JohnMichl.com |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Fill an Array with String values
You can do one of a number of things. E.g.:
Dim a a = Array("String1", "String2", "String3") a will seem to be an Array of type Variant() [i.e., that's what Typename(a) will return], though many (most?) people describe it as a Variant variable containing an array of strings. Nevertheless, If TypeName(a) = "Variant" Then MsgBox "Variant variable" Else MsgBox "Variant array" End If will display Variant array. In current versions, xl2000 and later, you can use Dim a() a = Array("String1", "String2", "String3" ....."String20") Once again, Typename(a) will return Variant() If the functions in the file at http://home.pacbell.net/beban are available to your workbook, you can use Dim a() As String Assign Array("String1", "String2", "String3"), a in which case a will be an array of type String() Alan Beban John Michl wrote: Simple question. How do I load a list of strings into an array? I know I code so the following but it seems inefficient. Dim a (1 to 20) as String a(1) = "String1" a(2) = "String2" etc... Can I do something like... a(1 to 20) = "String1", "String2", "String3" ....."String20" or a = Array("String1", "String2", "String3" ....."String20" ) Thanks. - John Michl www.JohnMichl.com |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Fill an Array with String values
For those who don't like loops per say, here is a "Poor mans" version of
List processing... Sub Demo() '// Dana DeLouis Dim v v = [Transpose("String" & Row(A1:A20))] End Sub -- Dana DeLouis Using Windows XP & Office XP = = = = = = = = = = = = = = = = = "John Michl" wrote in message ... Simple question. How do I load a list of strings into an array? I know I code so the following but it seems inefficient. Dim a (1 to 20) as String a(1) = "String1" a(2) = "String2" etc... Can I do something like... a(1 to 20) = "String1", "String2", "String3" ....."String20" or a = Array("String1", "String2", "String3" ....."String20" ) Thanks. - John Michl www.JohnMichl.com |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Fill an Array with String values
Dana DeLouis wrote:
For those who don't like loops per say, here is a "Poor mans" version of List processing... Sub Demo() '// Dana DeLouis Dim v v = [Transpose("String" & Row(A1:A20))] End Sub or v = ["String" & Column(A1:T1)] Alan Beban |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Fill an Array with String values
Or v = ["String" & Column(A:T)]
--- Regards, Norman Jones "Alan Beban" wrote in message ... Dana DeLouis wrote: For those who don't like loops per say, here is a "Poor mans" version of List processing... Sub Demo() '// Dana DeLouis Dim v v = [Transpose("String" & Row(A1:A20))] End Sub or v = ["String" & Column(A1:T1)] Alan Beban |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
last number array from string | Excel Worksheet Functions | |||
Variant Array with String Values - Type Mismatch | Excel Programming | |||
String to Array Conversion | Excel Programming | |||
Convert a string to an array | Excel Programming | |||
Convert a string to an array | Excel Programming |