hello all! i am learning to code, and have 7 books but still have such a hard time understanding loops. i'm desperate for help.
My boss wants me to loop through a years worth of files and pull data. I tried for days, and am just not retaining the rules behind the action. I hope someone will just build for me in the meantime. I promise i'm not lazy.
this is what i need each file to perform. Each file has the same sheet names.
i need to open each sheet, add a totals sheet, and then copy that information in a separate sheet after the last row of data that was collected. i hope at the end to have the full years totals.
the problem is i have 12 folders with 30 files - each with a different date.
I'm not understanding how to make an array understand what file to open and then keep that file name to perform the actions.
My boss wants me to loop through a years worth of files and pull data. I tried for days, and am just not retaining the rules behind the action. I hope someone will just build for me in the meantime. I promise i'm not lazy.
this is what i need each file to perform. Each file has the same sheet names.
i need to open each sheet, add a totals sheet, and then copy that information in a separate sheet after the last row of data that was collected. i hope at the end to have the full years totals.
the problem is i have 12 folders with 30 files - each with a different date.
I'm not understanding how to make an array understand what file to open and then keep that file name to perform the actions.
Code:
Sub TEST1()
Dim OpenPath As String
Dim OpenName As String
Dim wb As Workbook
Dim J As Integer
Dim Newname As String
Dim cell As Range
Dim LastRow As Long
' Windows("numbers for management.xlsx").Activate
' Set destRng = Sheets("TOTALS").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
''-------- below is the repeat
Sheets("Data").ShowAllData
With ThisWorkbook
.Sheets.Add(After:=.Sheets(.Sheets.Count)).Name = "TOTALS"
End With
Range("A1").Select
ActiveCell.FormulaR1C1 = "Date"
Range("B1").Select
ActiveCell.FormulaR1C1 = "File Name"
Range("C1").Select
ActiveCell.FormulaR1C1 = "Invoices Registered"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Total Open"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Total Invoices"
Range("F1").Select
ActiveCell.FormulaR1C1 = "DataInt"
Range("G1").Select
ActiveCell.FormulaR1C1 = "DataExt"
Range("H1").Select
ActiveCell.FormulaR1C1 = "Sum"
Range("I1").Select
ActiveCell.FormulaR1C1 = "BackInt"
Range("J1").Select
ActiveCell.FormulaR1C1 = "BackExt"
Range("K1").Select
ActiveCell.FormulaR1C1 = "Sum"
Range("L1").Select
ActiveCell.FormulaR1C1 = "Assigned"
Range("A2").Select
ActiveCell.FormulaR1C1 = "=Data!RC[19]"
Range("D2").Select
ActiveCell.FormulaR1C1 = "=COUNT(Data!C[3])"
Range("F2").Select
ActiveCell.FormulaR1C1 = "=COUNT(Data!C[21])"
Range("G2").Select
ActiveCell.FormulaR1C1 = "=COUNT(Data!C[21])"
Range("H2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=RC[-2]+RC[-1]"
Range("I2").Select
ActiveCell.FormulaR1C1 = "=backup!C[18]"
Range("I2").Select
ActiveCell.FormulaR1C1 = "=COUNT(backup!C[18])"
Range("J2").Select
ActiveCell.FormulaR1C1 = "=COUNT(backup!C[18])"
Range("K2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=RC[-2]+RC[-1]"
Range("L2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=RC[-4]-RC[-1]"
' Range("A2:L2").Select
' Selection.Copy
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Range("A1:L" & LastRow).Copy Destination:=destRng
End If
'Next wb
End Sub