Scenario: I am reading through folders and subfolders of a directory, if the found file is an ".xls" it opens. I then run another condition that, if true, will try to pass some values to the array.
Objective: I am defining my array without dimensions, because I don't know how many files will feed into it. For each file that fulfills the conditions, I am trying to get 3 values (name, path, date) and add to the array. Each file would be added to a new row of the array.
Ex. of array:
If 3 files fulfill the condition...
name1 path1 date1
name2 path2 date2
name3 path3 date3
Issue: when I run, I get a subscript out of range error when I try to pass the values to the array. How can I fix that?
Code1: This starts the loop through folders
Public Sub getInputFileInfo()
Dim FileSystem As Object
Dim HostFolder As String
' User selects where to search for files:
HostFolder = GetFolder()
Set FileSystem = CreateObject("Scripting.FileSystemObject")
DoFolder FileSystem.GetFolder(HostFolder)
End Sub
Code2: This gets the data:
Public Sub DoFolder(Folder)
Dim strFilename As String, filePath As String
Dim dateC As Date
Dim oFS As Object
Dim outputarray() As Variant
Dim ii As Long, lRow As Long, lCol As Long, lRow2 As Long
Dim w2, w As Workbook
Set w = ThisWorkbook
ii = 1
Dim SubFolder
For Each SubFolder In Folder.SubFolders
DoFolder SubFolder
Next SubFolder
Dim File
For Each File In Folder.Files
Set oFS = CreateObject("Scripting.FileSystemObject")
'Set w2 = File
filePath = File.Path
strFilename = File.Name
dateC = File.dateCreated
If InStr(LCase(File.Path), LCase("xls")) <> 0 Then
Set w2 = Workbooks.Open(filePath)
For lRow2 = 1 To w2.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
If w2.Sheets(1).Range("A" & lRow2).Value = "Test Name" Then
outputarray(0, ii) = strFilename ' THE ERROR STARTS HERE
outputarray(1, ii) = filePath
outputarray(2, ii) = dateC
ii = ii + 1
End If
Next lRow2
w2.Close False
End If
Set oFS = Nothing
Next File
For lRow = 1 To UBound(outputarray, 1)
For lCol = 1 To UBound(outputarray, 2)
w.Sheets("ControlSheet").Cells(lRow, lCol).Value = outputarray(lRow, lCol).Value
Next lCol
Next lRow
End Sub
I would use a dictionary and a "class" like in the following example.
The class fInfo looks like that
Option Explicit
Public fileName As String
Public filepath As String
Public fileDateCreated As Date
Then you could test it like that
Sub AnExample()
Dim dict As New Scripting.Dictionary
Dim fInfo As fileInfo
Dim filepath As String
Dim strFilename As String
Dim dateC As Date
Dim i As Long
For i = 1 To 2
filepath = "Path\" & i
strFilename = "Name" & i
dateC = Now + 1
Set fInfo = New fileInfo
With fInfo
.filepath = filepath
.fileName = strFilename
.fileDateCreated = dateC
End With
dict.Add i, fInfo
Next i
For i = 1 To dict.Count
With dict.Item(i)
Debug.Print .filepath, .fileName, .fileDateCreated
End With
Next i
End Sub
In your code maybe like that
For lRow2 = 1 To w2.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
If w2.Sheets(1).Range("A" & lRow2).Value = "Test Name" Then
Set fInfo = New fileInfo
With fInfo
.filepath = filepath
.fileName = strFilename
.fileDateCreated = dateC
End With
dict.Add ii, fInfo
' outputarray(0, ii) = strFilename ' THE ERROR STARTS HERE
' outputarray(1, ii) = filepath
' outputarray(2, ii) = dateC
' ii = ii + 1
End If
Next lRow2
try with these steps:
1) temporarily size the array to the maximum number of files
2) keep track of found files
3) finally resize array to actual number of found files
As follows (I only show relevant snippet):
ii = -1 '<<< initialize the counter fo found files to -1: it's more convenient for its subsequent updating and usage
ReDim outputarray(0 To 2, 0 To Folder.Files.Count) As Variant ' <<< temporarily size the array to the maximum number of files
For Each File In Folder.Files
Set oFS = CreateObject("Scripting.FileSystemObject")
'Set w2 = File
filePath = File.Path
strFilename = File.Name
dateC = File.dateCreated
If InStr(LCase(File.Path), LCase("xls")) <> 0 Then
Set w2 = Workbooks.Open(filePath)
For lRow2 = 1 To w2.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
If w2.Sheets(1).Range("A" & lRow2).Value = "Test Name" Then
ii = ii + 1 '<<< update the number of found files
outputarray(0, ii) = strFilename
outputarray(1, ii) = filePath
outputarray(2, ii) = dateC
End If
Next lRow2
w2.Close False
End If
Set oFS = Nothing
Next File
ReDim Preserve outputarray(0 To 2, 0 To ii) As Variant '<<< finally resize array to actual number of found files
edit
BTW you can avoid the double nested writing loops and use a one shot statement:
w.Sheets("ControlSheet").Range("A1").Resize(UBound(outputarray, 1) + 1, UBound(outputarray, 2) + 1).Value = outputarray
Related
For whatever reason, when I print arr_in(1, 1) it gives me the value of arr_out(1, 1). Any clue as to why this might be happening?
Sub conceptos_import()
Dim wb As Workbook
Dim wb_in As Workbook
Dim wb_out As Workbook
Dim ws_in As Worksheet
Dim ws_out As Worksheet
Dim clls_in As Range
Dim clls_out As Range
Dim str As String
Dim str_in As String
Dim str_out As String
Dim path As String
Dim i As Long
Dim i_in As Long
Dim i_out As Long
Set wb = Application.Workbooks("rn_macros.xlsm")
path = wb.path & "\"
str = Application.GetOpenFilename()
Set wb_in = Application.Workbooks.Open(str)
Set ws_in = wb_in.Worksheets(1)
Set wb_out = Application.Workbooks.Open(path & "files\conceptos.xlsx")
Set ws_out = wb_out.Worksheets(1)
Set ws_in = wb_in.Worksheets(1)
Set ws_out = wb_out.Worksheets(1)
Dim arr_in() As Variant
With ws_in
Set clls_in = .Range(.Cells(1, 1), .Cells(lr(ws_in, 1), 1))
End With
arr_in = clls_in.Value2
Dim arr_out() As Variant
With ws_out
Set clls_out = .Range(.Cells(1, 1), .Cells(lr(ws_out, 1), 1))
End With
arr_out = clls_out.Value2
Debug.Print arr_in(1, 1)
For i_out = UBound(arr_out) To LBound(arr_out) + 1 Step -1
i = 0
str_out = arr_out(i_out, 1)
For i_in = UBound(arr_in) To LBound(arr_in) + 1 Step -1
str_in = arr_in(i_in, 1)
If str_out = str_in Then
i = 1
Exit For
End If
Next i_in
If i = 0 Then
ws_out.Cells(i_out, 1).EntireRow.Delete
End If
Next i_out
End Sub
All variables are properly defined in the sub (all wb_'s as workbooks, ws_'s as worksheets, clls_'s as ranges).
The lr function is a user defined function that uses the End.xlUp method to find last row, taking target worksheet and column as the input:
Public Function lr(ws As Worksheet, col As Long) As Long
lr = ws.Cells(ws.rows.Count, col).End(xlUp).row
End Function
Found the issue, and even though it is poorly written code, I don't understand why it was causing the arrays to misfire:
str = Application.GetOpenFilename()
Set wb_in = Application.Workbooks.Open(str)
Set ws_in = wb_in.Worksheets(1) 1st a
Set wb_out = Application.Workbooks.Open(path & "files\conceptos.xlsx")
Set ws_out = wb_out.Worksheets(1) 1st b
Set ws_in = wb_in.Worksheets(1) 2nd a
Set ws_out = wb_out.Worksheets(1) 2nd b
As you can see the lines Set ws_in =... and Set ws_out =... are repeated. By deleting the redundant lines I was able to get it to work. The final code would look like this:
Sub conceptos_import()
Dim wb As Workbook
Dim wb_in As Workbook
Dim wb_out As Workbook
Dim ws_in As Worksheet
Dim ws_out As Worksheet
Dim clls_in As Range
Dim clls_out As Range
Dim str As String
Dim str_in As String
Dim str_out As String
Dim path As String
Dim i As Long
Dim i_in As Long
Dim i_out As Long
Set wb = Application.Workbooks("rn_macros.xlsm")
path = wb.path & "\"
str = Application.GetOpenFilename()
Set wb_in = Application.Workbooks.Open(str)
Set ws_in = wb_in.Worksheets(1)
Set wb_out = Application.Workbooks.Open(path & "files\conceptos.xlsx")
Set ws_out = wb_out.Worksheets(1)
Dim arr_in() As Variant
With ws_in
Set clls_in = .Range(.Cells(1, 1), .Cells(lr(ws_in, 1), 1))
End With
arr_in = clls_in.Value2
Dim arr_out() As Variant
With ws_out
Set clls_out = .Range(.Cells(1, 1), .Cells(lr(ws_out, 1), 1))
End With
arr_out = clls_out.Value2
For i_out = UBound(arr_out) To LBound(arr_out) + 1 Step -1
i = 0
str_out = arr_out(i_out, 1)
For i_in = UBound(arr_in) To LBound(arr_in) + 1 Step -1
str_in = arr_in(i_in, 1)
If str_out = str_in Then
i = 1
Exit For
End If
Next i_in
If i = 0 Then
ws_out.Cells(i_out, 1).EntireRow.Delete
End If
Next i_out
End Sub
Code below - copy the last 2 rows data of each workbook files in a folder then paste it all to Master workbook.
Problem 1 - can someone help on how get the codes below copy only the last row of each workbook.
Problem 2 - instead of copying from Col A to last Column of Data, I want to copy only specific columns e.g. Columns A to F, J and M.
Appreciate any help thanks.
Option Explicit
Sub OpenEachFiles_CopyLastRow_PasteToMaster()
Dim fso, fldr, fName As Object, Cnt, Cnt2, Cnt3, Cnt4, lRow, lCol As Long
Dim ws As Worksheet, rngArray() As Variant, rng As Range
On Error GoTo Errorfix
Cnt2 = 1 'dimension array
Cnt3 = 0 'array positions
Set fso = CreateObject("scripting.filesystemobject")
Set fldr = fso.GetFolder("C:\Users\Tope\Desktop\Data")
For Each fName In fldr.files
If fName.Name Like "*.xls*" Then
Workbooks.Open Filename:=fName
For Each ws In Workbooks(fName.Name).Sheets
If LCase(ws.Name) = LCase("Data") Then
With Sheets("Data")
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
lCol = .Cells(lRow, .Columns.Count).End(xlToLeft).Column
End With
Cnt2 = Cnt2 + 1
ReDim Preserve rngArray(Cnt2)
With Workbooks(fName.Name).Sheets(ws.Name)
Set rng = .Range(.Cells(lRow - 1, 1), .Cells(lRow, lCol))
End With
rngArray(Cnt3) = rng
Cnt3 = Cnt3 + 1
End If
Next ws
Workbooks(fName.Name).Close SaveChanges:=False
End If
Next fName
Cnt = 2
For Cnt4 = 0 To Cnt3 - 1
With ThisWorkbook.Sheets("Master")
.Range(.Cells(Cnt, "A"), .Cells(Cnt + 1, lCol)) = rngArray(Cnt4)
End With
Cnt = Cnt + 2
Next Cnt4
Errorfix:
If Err.Number <> 0 Then
On Error GoTo 0
MsgBox "Error"
End If
Set fldr = Nothing
Set fso = Nothing
End Sub
Assigning word document lines of text to an array to then print into an excel column. I want to print each item in array to it's own cell.
Currently, all the items are storying correctly into the array, but it's only printing the first item over and over Action
Code:
Option Explicit
Sub ParaCopy()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Set wApp = CreateObject("Word.Application")
Set wDoc = wApp.Documents.Open("J:\Data Dictionary.docx", ReadOnly:=True)
Dim wPara As Word.Paragraph
Dim arr() As Variant
Dim i As Long
i = 0
For Each wPara In wDoc.Paragraphs
If wPara.Range.Words.Count > 1 Then
ReDim Preserve arr(i)
arr(i) = wPara.Range
End If
i = i + 1
Next wPara
For i = LBound(arr) To UBound(arr)
[a1].Resize(UBound(arr) + 1) = arr
Next i
End Sub
EDIT: Need to separate each block of text separated by a space (outlined in blue) to this
Create a 2D array with one column and load that:
Option Explicit
Sub ParaCopy()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Set wApp = CreateObject("Word.Application")
Set wDoc = wApp.Documents.Open("J:\Data Dictionary.docx", ReadOnly:=True)
Dim wPara As Word.Paragraph
Dim arr() As Variant
ReDim arr(1 To wDoc.Paragraphs.Count, 1 To 1)
Dim i As Long
i = 1
For Each wPara In wDoc.Paragraphs
If wPara.Range.Words.Count > 1 Then
arr(i, 1) = wPara.Range
i = i + 1
End If
Next wPara
[a1].Resize(UBound(arr) + 1) = arr
End Sub
Copy Word Paragraphs to Excel Cells Using an Array
The number of rows of the array is wDoc.Paragraphs.Count which may differ from r (the 'actual count') hence you have to use r with Resize, and not wDoc.Paragraphs.Count or UBound(Data, 1).
Don't forget to Close the Document and Quit the App.
The first solution is early-bound and needs the library reference. When using it, just use
Set wApp = New Word.Application.
The second solution is late-bound and doesn't need the library reference. Also, it has been 'stripped off' the document and application variables (not necessary, you can declare them As Object).
Option Explicit
' e.g. Tools>References>Microsoft Word 16.0 Object Library
Sub ParaCopy()
Const FilePath As String = "J:\Data Dictionary.docx"
Dim wApp As Word.Application: Set wApp = Set wApp = New Word.Application
Dim wDoc As Word.Document: Set wDoc = wApp.Documents.Open(FilePath, , True)
Dim Data As Variant: ReDim Data(1 To wDoc.Paragraphs.Count, 1 To 1)
Dim wPara As Word.Paragraph
Dim r As Long
For Each wPara In wDoc.Paragraphs
If wPara.Range.Words.Count > 1 Then
r = r + 1
Data(r, 1) = wPara.Range
End If
Next wPara
wDoc.Close False
wApp.Quit
[a1].Resize(r) = Data
End Sub
Sub ParaCopyNoReference()
Const FilePath As String = "J:\Data Dictionary.docx"
With CreateObject("Word.Application")
With .Documents.Open(FilePath, , True)
Dim Data As Variant: ReDim Data(1 To .Paragraphs.Count, 1 To 1)
Dim wPara As Object
Dim r As Long
For Each wPara In .Paragraphs
If wPara.Range.Words.Count > 1 Then
r = r + 1
Data(r, 1) = wPara.Range
End If
Next wPara
.Close False
End With
.Quit
End With
[a1].Resize(r) = Data
End Sub
I have a database of about 140,000 test files. I am looking to loop through each folder and pull information from the file name of text and excel files so as to organize the data a little better.
I have found ways to pick a folder path and import information about each file using the code below. This works great except I would like to only pull information from excel and text files and I would also like to pull additional text information from the filename as well. For example I might have a file named:
"444555_CAT1010EL_650-700-800C-2hr laging NOT CH4.txt"
And I would want to print:
the 6 numbers at the beginning of the name (they could be anything) in this example "444555" in one column
print the 3 letters (they could be anything) before "1010EL" in another column. In this example "CAT"
"CH4" in the final column OR even have a column for "CH4" and if the filename contains "CH4" put an X in that column
have a column for "laging" and if the filename contains "laging" anywhere put an X in that column
Thank you in advance for your help.
Sub Compile3()
Dim oShell As Object
Dim oFile As Object
Dim oFldr As Object
Dim lRow As Long
Dim iCol As Integer
Dim vArray As Variant
vArray = Array(10, 0, 1, 156, 2, 4, 144, 146, 183, 185)
'0=Name, 31=Dimensions, 1=Size, 163=Vertical Resolution
Set oShell = CreateObject("Shell.Application")
'-------------------ROW INFO INPUT OPTIONS-----------------
'' 1)
' lRow = 1
' 2) find first empty row in database for bottletracker
'
Dim iRow As Long
iRow = Cells.find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
lRow = iRow
'------------------------------------------------------------
With Application.FileDialog(msoFileDialogFolderPicker)
.title = "Select the Folder..."
If .Show Then
Set oFldr = oShell.Namespace(.SelectedItems(1))
With oFldr
'Column header information
For iCol = LBound(vArray) To UBound(vArray)
Cells(lRow, iCol + 4) = .getdetailsof(.items, vArray(iCol))
Next iCol
For Each oFile In .items
lRow = lRow + 1
For iCol = LBound(vArray) To UBound(vArray)
Cells(lRow, iCol + 4) = .getdetailsof(oFile, vArray(iCol))
Next iCol
Next oFile
End With
End If
End With
End Sub
I'd use this code. There's three separate procedures at the end that find the last cell on the sheet, return the folder and return all files within the folder.
The main code then looks at each file name and pulls the required information from it.
Note, this code: InStr(sFileName, "CAT") <> 0 will return TRUE/FALSE depending if the text "CAT" is within the file name. InStr(sFileName, "CAT") returns the position of "CAT" within the text, and <>0 turns that into a boolean depending on if it's different from 0.
Option Explicit
Public Sub Test()
Dim sFolder As String
Dim cFiles As Collection
Dim vFile As Variant
Dim sFileName As String
Dim rLastCell As Range
sFolder = GetFolder("S:\DB_Development_DBC\") & Application.PathSeparator
Set cFiles = New Collection
EnumerateFiles sFolder, "*.xls*", cFiles
EnumerateFiles sFolder, "*.txt", cFiles
With ThisWorkbook.Worksheets("Sheet1")
For Each vFile In cFiles
Set rLastCell = LastCell(ThisWorkbook.Worksheets("Sheet1")).Offset(1) 'Find last row
sFileName = Mid(vFile, InStrRev(vFile, Application.PathSeparator) + 1) 'Get just file name from path.
.Cells(rLastCell.Row, 1) = Left(sFileName, 6) 'First 6 characters.
.Cells(rLastCell.Row, 2) = Mid(sFileName, InStr(sFileName, "1010EL") - 3, 3) '3 characters before 1010EL.
.Cells(rLastCell.Row, 3) = InStr(sFileName, "CH4") <> 0 'Contains CH4.
.Cells(rLastCell.Row, 4) = InStr(sFileName, "laging") <> 0 'Contains laging.
Next vFile
End With
End Sub
Sub EnumerateFiles(ByVal sDirectory As String, _
ByVal sFileSpec As String, _
ByRef cCollection As Collection)
Dim sTemp As String
sTemp = Dir$(sDirectory & sFileSpec)
Do While Len(sTemp) > 0
cCollection.Add sDirectory & sTemp
sTemp = Dir$
Loop
End Sub
Function GetFolder(Optional startFolder As Variant = -1) As Variant
Dim fldr As FileDialog
Dim vItem As Variant
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
If startFolder = -1 Then
.InitialFileName = Application.DefaultFilePath
Else
If Right(startFolder, 1) <> "\" Then
.InitialFileName = startFolder & "\"
Else
.InitialFileName = startFolder
End If
End If
If .Show <> -1 Then GoTo NextCode
vItem = .SelectedItems(1)
End With
NextCode:
GetFolder = vItem
Set fldr = Nothing
End Function
Public Function LastCell(wrkSht As Worksheet, Optional Col As Long = 0) As Range
Dim lLastCol As Long, lLastRow As Long
On Error Resume Next
With wrkSht
If Col = 0 Then
lLastCol = .Cells.Find("*", , , , xlByColumns, xlPrevious).Column
lLastRow = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
Else
lLastCol = .Cells.Find("*", , , , xlByColumns, xlPrevious).Column
lLastRow = .Columns(Col).Find("*", , , , xlByColumns, xlPrevious).Row
End If
If lLastCol = 0 Then lLastCol = 1
If lLastRow = 0 Then lLastRow = 1
Set LastCell = wrkSht.Cells(lLastRow, lLastCol)
End With
On Error GoTo 0
End Function
Edit:
I've updated the code to include the other requirements and moved finding the last cell to within the loop so it actually works.
Note:
Mid(sFileName, InStr(sFileName, "1010EL") - 3, 3) - this code will throw an error if the text doesn't contain 1010EL. Add a check that InStr(sFileName, "1010EL") <> 0 before letting that line execute.
I have to read an excel which can have 'n' rows and 'n' columns and store the data in an array for processing.
For example the below:
Author Book No Value
ABC A 1 100
DEF D 2 20
I want to take the headers in a separate array and the Information rows in another.
Here is what I have so far:
Assuming the data starts from Row 13 in the excel worksheet-
var i, j, k ,l,m ,n;
i=13; j=1, k=0; m=0; n=0; // i represents the row and j represents excel column(A)
while(EApp.ActiveSheet.Cells(12,j).Value!="")
{
j=j+1; // Counting the Number of Columns (Header)
}
j=j-1; //decrementing the counter j by 1
k=j;
while(j!=0)
{
ArrField[j]=EApp.ActiveSheet.Cells(12,j).Value;
j=j-1;
}
This is what I tried, output is as expected, but is there a better way to code this? preferably with lesser variables.
while(EApp.ActiveSheet.Cells(i,1).Value!="undefined")
{
m=k;
j=0;
ArrData[i]=new Array(m);
while(m!=0)
{
ArrData[n][j]=EApp.ActiveSheet.Cells(i,m).Value;
m=m-1;
j=j+1;
}
n=n+1;
i=+1;
}
Also I need to read the arrays and store them into corresponding fields of another system. I'm a bit lost over here.
Sample Code: (Something like this)
SetFieldValue(ArrField[0],ArrData[0][0]);
Array Output:
Value,No,Book,Author (Header got in reverse order)
100,1,A,ABC,20,2,D,DEF (2 rows of Data also got in reverse order)
Any suggestions experts?
you can use csv's as dynamic arrays in a quite nice way.
Here is my example code. I suggest to rewrite it to your needs and add some errorhandling.
Here is the table data:
ID AUTHOR BOOK NO VALUE
1 ABC A 1 100
2 DEFG D 2 20
3 XYZ Q 3 55
Here is the code:
Sub test1()
Dim arrayname As String
Dim mytestW As Variant
Dim mytestR As Variant '-->your array you can work with
'give your array a arrayname = authorbook (for example)
arrayname = "authorbook"
mytestW = dataintoarray(arrayname)
mytestR = AsArray(arrayname, 2) '-->get the second row
End Sub
And here are the functions:
Function dataintoarray(myarray As String) As Variant
Dim res As Variant
Dim wb As Workbook, ws As Worksheet
Dim LastRow As Long, LastCol As Long
Dim iRow As Integer, jCol As Integer
Dim OutputFileNum As Integer
Dim PathName As String
Dim Line As String
Line = ""
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Sheet1")
PathName = Application.ActiveWorkbook.Path
OutputFileNum = FreeFile
Open PathName & "\" & myarray & ".csv" For Output Lock Write As #OutputFileNum
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
LastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
For iRow = 1 To LastRow
For jCol = 1 To LastCol
Line = Line & ws.Cells(iRow, jCol).Value & ","
Next jCol
Print #OutputFileNum, Line
Line = ""
Next iRow
Close OutputFileNum
End Function
Function AsArray(myarray As String, index As Integer) As Variant
Dim res As Variant
Dim wb As Workbook, ws As Worksheet
Dim objFSO As Object, objFile As Object
Dim sLine As String
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Sheet1")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(Application.ActiveWorkbook.Path & "\" & myarray & ".csv", 1)
Do Until objFile.AtEndOfStream
sLine = objFile.ReadLine
'the col of the ID = 0
If Split(sLine, ",")(0) = index Then
AsArray = Split(sLine, ",")
End If
Loop
objFile.Close
End Function
Now you have your dynamic array saved in mytestR.
You can play with it like so:
?mytestR(0)
2
?mytestR(1)
DEFG
?mytestR(2)
D
?mytestR(3)
2
?mytestR(4)
20