I've now realized my original organizational method is not adequate, so I want to add all the information to a new worksheet called ("RAW")
I am trying to create a Do Loop based a table row count. Here, I'm looping from one "theFILE.xlsm" which opens workbooks one at a time. When the workbook is open I want to copy
Here is what I want to do:
- Open a workbook (sFile),
- Count Table2's databodyrange.count,
- Assign the count to a Variable called BodyCount,
- Copy & Paste desired row,
- Loop for BodyCount's number of times
Every workbook that will be opened has a Table2 but none of the tables are completed so I can't rely if a cell is <> "" as I did with the first Do While Loop.
How do I create a loop to copy 1 row at a time based on the amount of rows in a table.
Here is what
Sub every_one() ''compile everything into 1 list
''''DIMENSIONS
Application.ScreenUpdating = False
Dim SourceRow As Long
Dim sFile As String
Dim wb As Workbook
Dim FileName1 As String
Dim FileName2 As String
Dim wksSource As Worksheet
Const scWkbSourceName As String = "theFILE.xlsm"
Set wkbSource = Workbooks(scWkbSourceName)
Set wksSource = wkbSource.Sheets("Sheet1")
Const wsOriginalBook As String = "theFILE.xlsm"
Const sPath As String = "U:\theFILES\" 
SourceRow = 5
DestinationColumn = 2
FirstDestinationRow = 1
SecondDestinationRow = 41
''ENSURE SELECT SOURCE SHEET
Sheets("Sheet1").Select
Do While Cells(SourceRow, "C").Value <> ""
    FileName1 = wksSource.Range("A" & SourceRow).Value
    FileName2 = wksSource.Range("L" & SourceRow).Value
    sFile = sPath & FileName1 & "\" & FileName2 & ".xlsm"
    ''OPEN FILE
    Set wb = Workbooks.Open(sFile)
''insert CODE TO LOOP
    ''DECLARE TABLE
    Dim tbl As ListObject
    Dim BodyCount As Long
    Dim StartingTablePosition As Long
    Set tbl = ActiveSheet.ListObjects("Table2")
    'start FOR, LOOP
    BodyCount = ActiveSheet.ListObjects("Table2").DataBodyRange.Rows.Count
    Dim WorkingRow As Long
    WorkingRow = 20
    For i = WorkingRow to WorkingRow + BodyCount Step 1
        'COPY "SourceRow" from "theFILE.xlsm"
    Windows("theFILE.xlsm").Activate
    Rows(SourceRow).Copy
        'PASTE to Compile Sheet, next available column & TRANSPOSE row into column
    Sheets("RAW").Cells.Item(FirstDestinationRow, DestinationColumn).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=True 
    
        'COPY ROW from "sFile" Table2
    wb.Activate
    Rows(WorkingRow).Copy
    Application.CutCopyMode = False
        'PASTE to Compile sheet, TRANSPOSE row into column
    Windows("theFILE 1.1.xlsm").Activate
    ActiveSheet.Cells.Item(SecondDestinationRow, DestinationColumn).Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=True
    DestinationColumn = DestinationColumn + 1
    Next i
''End custom code for desired loop operation
''CLOSE WORKBOOK W/O BEFORE SAVE
wb.Activate
Application.EnableEvents = False
ActiveWorkbook.Save
Application.EnableEvents = True
ActiveWorkbook.Close savechanges:=False
Windows("theFILE.xlsm").Activate
Sheets("Sheet1").Select
''GO TO NEXT .xlsm FILE
SourceRow = SourceRow + 1
Loop
End Sub
I am new to For...Next Loops. Any and all tips, tricks or hints will be greatly appreciated.



 
     
    