trishcollins
Board Regular
- Joined
- Jan 7, 2006
- Messages
- 71
I am having trouble working with a 2 dimensional array. I have worked with a 1D array before, no problem. The Named Table I am loading from is called "EA-Libraries_Data", and it contains the list of the other tables on the same sheet that need to be populated. There are 3 tables. The second column of that table contains the drive letter to be used to find the data.
EA Libraries Drive
EA_WIP_DIR R:\
EASV2_DIR S:\
EA_Official_Dir T:\
I am trying to populate the three tables on the page with the subfolder names. I want to assign the EA Libraries name to the MyArrayTable variable, and the Drive to the MyArrayDir, so that as it goes through each loop, it takes the next Table name and the next Drive name. The only issue is, I can't seem to figure out how to reference the second column of the array. Here is the code:
EA Libraries Drive
EA_WIP_DIR R:\
EASV2_DIR S:\
EA_Official_Dir T:\
I am trying to populate the three tables on the page with the subfolder names. I want to assign the EA Libraries name to the MyArrayTable variable, and the Drive to the MyArrayDir, so that as it goes through each loop, it takes the next Table name and the next Drive name. The only issue is, I can't seem to figure out how to reference the second column of the array. Here is the code:
Code:
Sub ListMyDir()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
Application.DisplayStatusBar = True
Application.StatusBar = "Importing Beehive Directories"
Dim tblrow As Integer
Dim myTable As ListObject
Dim MyArray As Variant
Dim TempArray As Variant
Dim MyArrayTable As String
Dim MyArrayDir As String
Dim x As Integer
Set myTable = ActiveSheet.ListObjects("EA_Libraries_Data")
TempArray = myTable.DataBodyRange
MyArray = Application.Transpose(TempArray)
tblrow = 1
On Error Resume Next
For x = 1 To 3
' assign the array library name and drive
[B] MyArrayTable = MyArray(x, 1)
MyArrayDir = MyArray(x, 2)[/B]
ActiveSheet.ListObjects(MyArrayTable).DataBodyRange.Delete
Set MyObject = New Scripting.FileSystemObject
'assign the array drive as the source
Set mySource = MyObject.GetFolder[B](MyArray(x, 2))[/B]
On Error Resume Next
For Each mySubFolder In mySource.SubFolders
For Each myFile In mySource.Files
ActiveSheet.ListObjects(MyArrayTable).ListRows.Add AlwaysInsert:=True
ActiveSheet.ListObjects(MyArrayTable).DataBodyRange(tblrow, 1).Value = MyArrayDir
tblrow = tblrow + 1
Next
Next
Next x
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.StatusBar = ""
Application.Calculation = xlCalculationAutomatic
End Sub