Hi All,
My following code works fine but the array is static. I want to make it dynamic. When I tried doing it, it shows error as subscription out of range. Can you please let me know where I am going wrong?
>>> use code - tags <<<
My following code works fine but the array is static. I want to make it dynamic. When I tried doing it, it shows error as subscription out of range. Can you please let me know where I am going wrong?
>>> use code - tags <<<
Code:
Option Explicit
Public Sub Button1_Click()
Dim i As Integer
Dim strPath As String
Dim strArr(1 To 999, 1 To 1) As String ' I want to make it dynamic array
Dim strFile As String
'ReDim strArr(1 To 999, 1 To 1)
Cells(8, 3).ClearContents
strPath = Sheet1.Cells(4, 3).Value
If Right(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
i = 1
strFile = Dir(strPath & "*")
Do While strFile <> vbNullString
'ReDim Preserve strArr(1 To i, 1 To 1)
strArr(i, 1) = strFile
strFile = Dir()
i = i + 1
Loop
Cells(8, 3).Resize(i) = strArr
End Sub
Last edited by a moderator: