Hello, I have one question regarding variable arrays to store string.
I'm trying to have the user enter the length of an array, and store a string (file name) into the array for use later. However, I get an error stating "constant expression required". Tried two different ways to set the variable length but no dice.
any help would be very appreciated.
I'm trying to have the user enter the length of an array, and store a string (file name) into the array for use later. However, I get an error stating "constant expression required". Tried two different ways to set the variable length but no dice.
Code:
[B][I][U]First try[/U][/I][/B]
[B][I][/I][/B]
Dim strFile As String
Dim lNum As Integer
lNum = Application.InputBox _
(Prompt:="How many files would you like to compare?", _
Title:="Hub's Trace", Type:=1)
For i = 0 To lNum - 1
strFile = Application.GetOpenFilename
myFiles(i) = strFile <-------- [COLOR=#ff0000]error: sub or function not defined [/COLOR]
[COLOR=#ff0000] [/COLOR]
Next i
Code:
[B][I][U]second try[/U][/I][/B]
Dim strFile As String
Dim lNum As Integer
lNum = Application.InputBox _
(Prompt:="How many files would you like to compare?", _
Title:="Hub's Trace", Type:=1)
Dim myFiles(1 To lNum) As Variant<------ [COLOR=red]error occurs here [/COLOR]
For i = 1 To lNum Step 1
myFiles(i) = i + 1
Next i
Cells(2, 3) = apllication.CountA(myFiles) 'to see how many values are stored: confirming code
Range("A1") = myFiles 'to list values stored in the array
any help would be very appreciated.