Hi
Code is below. All source spreadsheets sit in C:\ABB
The Destination workbook is C:\ABB\ABBPipelineReport.xls, Worksheet is
"Report".
You can see the name of each workbook in the code below i.e
SalesCurrentMonth, SalesPreviousMonth,SalesPreviousMonth-1,
SalesPreviousMonth-2 etc
The vba is in the Destination workbook.
Their are other source workbooks in C:\ABB
You will also notice that for some reason the 11th and 12th formulas for the
11th and 12th month of Sales open the external workbook. this is because only
these 2 formulas return #REF! if I dont. The previous 10 work fine without
opening external workbooks.
Hopes this all makes sense, thanks again for your help.
Simon
'Lookup Current Month Sales
Range("J4").Select
Selection.FormulaArray = _
"=SUM(IF('C:\ABB\[SalesCurrentMonth.xls]Category by Customer - Excel
Ex'!R6C10:R263C10=RC1,'C:\ABB\[SalesCurrentMonth.xls]Category by Customer -
Excel Ex'!R6C14:R263C14,0))"
Selection.AutoFill Destination:=Range("J4:J" & LR), Type:=xlFillDefault
Range("J3").Select
ActiveCell.FormulaR1C1 = "Current Month"
'Lookup Previous Month Sales
Range("K4").Select
Selection.FormulaArray = _
"=SUM(IF('C:\ABB\[SalesPreviousMonth.xls]Category by Customer -
Excel Ex'!R6C10:R263C10=RC1,'C:\ABB\[SalesPreviousMonth.xls]Category by
Customer - Excel Ex'!R6C14:R263C14,0))"
Selection.AutoFill Destination:=Range("K4:K" & LR), Type:=xlFillDefault
Range("K3").Select
ActiveCell.FormulaR1C1 = "Previous Month"
'Lookup Previous Month-1 Sales
Range("L4").Select
Selection.FormulaArray = _
"=SUM(IF('C:\ABB\[SalesPreviousMonth-1.xls]Category by Customer -
Excel Ex'!R6C10:R263C10=RC1,'C:\ABB\[SalesPreviousMonth-1.xls]Category by
Customer - Excel Ex'!R6C14:R263C14,0))"
Selection.AutoFill Destination:=Range("L4:L" & LR), Type:=xlFillDefault
Range("L3").Select
ActiveCell.FormulaR1C1 = "Previous Month-1"
'3 Month Rolling Average
Columns("I:I").Select
Selection.NumberFormat = "0"
Range("I4").Select
ActiveCell.FormulaR1C1 = "=AVERAGE(RC[1]:RC[3])"
Range("I4").Select
Selection.AutoFill Destination:=Range("I4:I" & LR), Type:=xlFillDefault
'Lookup Previous Month-2 Sales
Range("M4").Select
Selection.FormulaArray = _
"=SUM(IF('C:\ABB\[SalesPreviousMonth-2.xls]Category by Customer -
Excel Ex'!R6C10:R263C10=RC1,'C:\ABB\[SalesPreviousMonth-2.xls]Category by
Customer - Excel Ex'!R6C14:R263C14,0))"
Selection.AutoFill Destination:=Range("M4:M" & LR), Type:=xlFillDefault
Range("M3").Select
ActiveCell.FormulaR1C1 = "Previous Month-2"
'Lookup Previous Month-3 Sales
Range("N4").Select
Selection.FormulaArray = _
"=SUM(IF('C:\ABB\[SalesPreviousMonth-3.xls]Category by Customer -
Excel Ex'!R6C10:R263C10=RC1,'C:\ABB\[SalesPreviousMonth-3.xls]Category by
Customer - Excel Ex'!R6C14:R263C14,0))"
Selection.AutoFill Destination:=Range("N4:N" & LR), Type:=xlFillDefault
Range("N3").Select
ActiveCell.FormulaR1C1 = "Previous Month-3"
'Lookup Previous Month-4 Sales
Range("O4").Select
Selection.FormulaArray = _
"=SUM(IF('C:\ABB\[SalesPreviousMonth-4.xls]Category by Customer -
Excel Ex'!R6C10:R263C10=RC1,'C:\ABB\[SalesPreviousMonth-4.xls]Category by
Customer - Excel Ex'!R6C14:R263C14,0))"
Selection.AutoFill Destination:=Range("O4:O" & LR), Type:=xlFillDefault
Range("O3").Select
ActiveCell.FormulaR1C1 = "Previous Month-4"
'Lookup Previous Month-5 Sales
Range("P4").Select
Selection.FormulaArray = _
"=SUM(IF('C:\ABB\[SalesPreviousMonth-5.xls]Category by Customer -
Excel Ex'!R6C10:R263C10=RC1,'C:\ABB\[SalesPreviousMonth-5.xls]Category by
Customer - Excel Ex'!R6C14:R263C14,0))"
Selection.AutoFill Destination:=Range("P4:P" & LR), Type:=xlFillDefault
Range("P3").Select
ActiveCell.FormulaR1C1 = "Previous Month-5"
'Lookup Previous Month-6 Sales
Range("Q4").Select
Selection.FormulaArray = _
"=SUM(IF('C:\ABB\[SalesPreviousMonth-6.xls]Category by Customer -
Excel Ex'!R6C10:R263C10=RC1,'C:\ABB\[SalesPreviousMonth-6.xls]Category by
Customer - Excel Ex'!R6C14:R263C14,0))"
Selection.AutoFill Destination:=Range("Q4:Q" & LR), Type:=xlFillDefault
Range("Q3").Select
ActiveCell.FormulaR1C1 = "Previous Month-6"
'Lookup Previous Month-7 Sales
Range("R4").Select
Selection.FormulaArray = _
"=SUM(IF('C:\ABB\[SalesPreviousMonth-7.xls]Category by Customer -
Excel Ex'!R6C10:R263C10=RC1,'C:\ABB\[SalesPreviousMonth-7.xls]Category by
Customer - Excel Ex'!R6C14:R263C14,0))"
Selection.AutoFill Destination:=Range("R4:R" & LR), Type:=xlFillDefault
Range("R3").Select
ActiveCell.FormulaR1C1 = "Previous Month-7"
'Lookup Previous Month-8 Sales
Range("S4").Select
Selection.FormulaArray = _
"=SUM(IF('C:\ABB\[SalesPreviousMonth-8.xls]Category by Customer -
Excel Ex'!R6C10:R263C10=RC1,'C:\ABB\[SalesPreviousMonth-8.xls]Category by
Customer - Excel Ex'!R6C14:R263C14,0))"
Selection.AutoFill Destination:=Range("S4:S" & LR), Type:=xlFillDefault
Range("S3").Select
ActiveCell.FormulaR1C1 = "Previous Month-8"
'Lookup Previous Month-9 Sales
Range("T4").Select
Selection.FormulaArray = _
"=SUM(IF('C:\ABB\[SalesPreviousMonth-9.xls]Category by Customer -
Excel Ex'!R6C10:R263C10=RC1,'C:\ABB\[SalesPreviousMonth-9.xls]Category by
Customer - Excel Ex'!R6C14:R263C14,0))"
Selection.AutoFill Destination:=Range("T4:T" & LR), Type:=xlFillDefault
Range("T3").Select
ActiveCell.FormulaR1C1 = "Previous Month-9"
Application.ScreenUpdating = False
Workbooks.Open(Filename:="C:\ABB\SalesPreviousMonth-9.xls", Origin:= _
xlWindows).RunAutoMacros Which:=xlAutoOpen
ActiveWorkbook.Close False
Application.ScreenUpdating = True
'Lookup Previous Month-10 Sales
Range("U4").Select
Selection.FormulaArray = _
"=SUM(IF('C:\ABB\[SalesPreviousMonth-10.xls]Category by Customer -
Excel Ex'!R6C10:R263C10=RC1,'C:\ABB\[SalesPreviousMonth-10.xls]Category by
Customer - Excel Ex'!R6C14:R263C14,0))"
Selection.AutoFill Destination:=Range("U4:U" & LR), Type:=xlFillDefault
Range("U3").Select
ActiveCell.FormulaR1C1 = "Previous Month-10"
Application.ScreenUpdating = False
Workbooks.Open(Filename:="C:\ABB\SalesPreviousMonth-10.xls", Origin:= _
xlWindows).RunAutoMacros Which:=xlAutoOpen
ActiveWorkbook.Close False
Application.ScreenUpdating = True
"OssieMac" wrote:
> Hi Simon,
>
> I need to see the code that you are using to get the data from the source
> workbooks.
>
> If you have not yet coded that part, then:
>
> How do I identify the source workbooks? Are they all in the one folder?
>
> Are the source workbooks the only workbooks in the source folder? If not then:
>
> Do the source workbook names follow a pattern so that I can use wildcards to
> identify and open each one in turn?
>
> What is the Sheet name and column in the source workbooks where you want to
> extract the data from.
>
> What is the Sheet name and column in the destination workbook? (I am
> assuming that you want the data in the destination workbook all in one column
> one under the other. Is this correct?)
>
> Where will the VBA code be located? (In the Destination workbook or in a
> workbook of its own?) If in a workbook of its own, what is the name of the
> destination workbook.
>
> There may be more questions once I see what you return to me so continue to
> monitor this thread as frequently as possible.
>
> --
> Regards,
>
> OssieMac
>
>