I'm currently looping through multiple files using the following code:
Dim wb As Workbook, sFile As String, sPath As String
Dim itm As Variant
Dim strFileNames As String
sPath = "C:\.......\Annual and Quarterly Budget Data\"
''Retrieve the current files in directory
sFile = Dir(sPath)
Do While sFile <> ""
strFileNames = strFileNames & "," & sFile
sFile = Dir()
Loop
''Open each file found
For Each itm In Split(strFileNames, ",")
If itm <> "" Then
Set wb = Workbooks.Open(sPath & itm)
'' DO LOTS OF CALCULATIONS HERE
End If
Next itm
Inside the loop, I have the following code, which does a SUMIF formula in one of my columns:
BD.Sheets("Sheet1").Cells(Rows.Count, 6).End(xlUp).Offset(1, 0).Formula = "=SUMIF( 'P:\Actuary\Cash Flow Forecast\Annual and Quarterly Budget Data\[ECMQA 2012Q1.xls]Sheet1'!$D$13:$D$" & LastRow & ",D" & BD.Sheets("Sheet1").Cells(Rows.Count, 6).End(xlUp).Offset(1, 0).Row & ",OFFSET('P:\Actuary\Cash Flow Forecast\Annual and Quarterly Budget Data\[ECMQA 2012Q1.xls]Sheet1'!$D$13:$D$" & LastRow & ",0,MATCH(E" & BD.Sheets("Sheet1").Cells(Rows.Count, 6).End(xlUp).Offset(1, 0).Row & ",'P:\Actuary\Cash Flow Forecast\Annual and Quarterly Budget Data\[ECMQA 2012Q1.xls]Sheet1'!$D$12:$R$12,0)-1))"
Since I am looping through all of the files, how would I change the part of the code with the file name (code below) to pick each new file and not a fixed one like I have above?
LastRow is 234 so the file and cell reference is:
'P:\Actuary\........\[ECMQA 2012Q1.xls]Sheet1'$D$13:$D$234
Each file has the same exact format.
PLEASE HELP!
Thank you!
Bookmarks