So I have a bit of code that looks for a value in other workbooks, sums them and posts the new value into the current workbook.
The number of workbooks needed to retrieve data from however is derived from user entered data in the current workbook. So I think I need to create a loop (or for/next) in order to dictate how many times an action needs performing.
Here is the code that I have at the moment which looks in 2 workbooks.
where NumLoops, is how many workbooks it should look through
The number of workbooks needed to retrieve data from however is derived from user entered data in the current workbook. So I think I need to create a loop (or for/next) in order to dictate how many times an action needs performing.
Here is the code that I have at the moment which looks in 2 workbooks.
Code:
Sub TestGetValue()
NumLoops = (Range("D2") - Range("D1")) / 7 + 1
WeekSNum = (Range("D1") - Range("G1")) / 7 + 1
p = "C:\\myfilelocation"
f = "Week_" & WeekSNum & " we_" & Format(Range("D1"), "ddmmyy") & "_ISSUED.xls"
s = "new cstm summary"
a = "C6"
V1 = GetValue(p, f, s, a)
p = "C:\\myfilelocation"
f = "Week_" & WeekSNum + 1 & " we_" & Format(Range("D1") + 7, "ddmmyy") & "_ISSUED.xls"
s = "summary"
a = "C6"
V2 = GetValue(p, f, s, a)
Sheets("Sheet2").Range("C5") = WorksheetFunction.Sum(V1, V2)
End Sub
where NumLoops, is how many workbooks it should look through