There are 2 sheets copied to a new workbook each time the macro is run - "Invoice" and the backing data ("Completes", "Aborts" etc).
Thanks again for your help.
There are 2 sheets copied to a new workbook each time the macro is run - "Invoice" and the backing data ("Completes", "Aborts" etc).
Thanks again for your help.
there's no need to select a sheet:
But this overwrites the same cell 7 times (?)![]()
For Each ws In Worksheets If ws.Name <> "Invoice" Then sheets("Invoice").Range("J22")="=" & ws.name & "!C[17]" next
Even better snb, thanks for your suggestion.
I'm using the following now (ADV sheets are a special case that need a bit extra info, and slightly amended formula to SUM):
-edit: The workbook will consist of 1 of the following 7 combinations of sheets:![]()
For Each ws In Worksheets If ws.Name <> "Invoice" Then Select Case ws.Name Case "ADV" Sheets("Invoice").Range("J22") = "=SUM(" & ws.Name & "!C[17])" Range("B2", Range("A65536").End(xlUp).Offset(, 1)).FormulaR1C1 = "=VLOOKUP(RC[-1],'[Timesheet import.xlsm]Completions'!C1:C2,2,0)" Range("B2", Range("A65536").End(xlUp).Offset(, 1)) = Range("B2", Range("A65536").End(xlUp).Offset(, 1)).Value Case Else Sheets("Invoice").Range("J22") = "=SUM(" & ws.Name & "!C[17])" End Select End If Next ws
"Invoice" and "Completes"
"Invoice" and "Aborts"
"Invoice" and ...
"Invoice" and ...
"Invoice" and ...
"Invoice" and ...
"Invoice" and ...
So the formula is only entered once on "Invoice" to sum the backing data.
Again, many thanks both for your help.
Last edited by tone640; 09-02-2011 at 06:58 AM. Reason: Clarifying, spelling
![]()
For Each ws In Worksheets If ws.Name <> "Invoice" Then Sheets("Invoice").Range("J22") = "=SUM(" & ws.Name & "!C[17])" if ws.Name="ADV" then with ws.Range("B2", ws.Range("A65536").End(xlUp).Offset(, 1)) .FormulaR1C1 = "=VLOOKUP(RC[-1],'[Timesheet import.xlsm]Completions'!C1:C2,2,0)" .value=.value end with End If end if Next
Last edited by snb; 09-02-2011 at 09:05 AM.
Thanks yet again, this has really helped my understanding.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks