Hi,
I've written a macro that works perfectly in Excel 07, it literally drops some data onto sheet "ShepherdBookedCases" and then refreshes the Pivot Table on sheet "Pivot"
Sadly the majority of people using this will be using Excel '03. I keep coming over an issue whereby the macro will run but then when i go to refresh the Pivot Table it tells me the "Reference is Not Valid"
The reference for the Pivot Table is deciphered by a named range which works on an OFFSET reference, namely
Any idea why this isn't working or what i can do to get around it??
2003
2007
I've written a macro that works perfectly in Excel 07, it literally drops some data onto sheet "ShepherdBookedCases" and then refreshes the Pivot Table on sheet "Pivot"
Sadly the majority of people using this will be using Excel '03. I keep coming over an issue whereby the macro will run but then when i go to refresh the Pivot Table it tells me the "Reference is Not Valid"
The reference for the Pivot Table is deciphered by a named range which works on an OFFSET reference, namely
Rich (BB code):
=OFFSET(ShepherdBookedCases!$A$1,0,0,COUNT(ShepherdBookedCases1!$A$1:$A$65536),17)
Any idea why this isn't working or what i can do to get around it??
2003
Rich (BB code):
Sub CMGMTShepherdBookedCases()
Application.ScreenUpdating = False
' Save As Output.xls to Desktop
Application.DisplayAlerts = False
ChDir "J:\Case Management\Reporting"
ActiveWorkbook.SaveAs Filename:= _
"J:\Case Management\Reporting\Output.xls", FileFormat:= _
xlExcel8, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
Application.DisplayAlerts = True
' Adds in Appointment Column
Range("O2").Select
ActiveCell.FormulaR1C1 = "Appointment"
Range("O3").Select
ActiveCell.FormulaR1C1 = "=TEXT(RC[-14],""DD-MMM"")"
' Autofills based on Col A minus 1
Range("O3").Select
Range("O3").AutoFill Destination:=Range("O3", Range("N3").End(xlDown).Offset(0, 1))
Range(ActiveCell, ActiveCell.End(xlDown)).Select
' Adds in Instruction Column
Range("P2").Select
ActiveCell.FormulaR1C1 = "Instruction"
Range("P3").Select
ActiveCell.FormulaR1C1 = "=TEXT(RC[-3],""DD-MMM"")"
' Autofills based on Col A minus 1
Range("P3").Select
Range("P3").AutoFill Destination:=Range("P3", Range("O3").End(xlDown).Offset(0, 1))
Range(ActiveCell, ActiveCell.End(xlDown)).Select
' Adds in SLA Column
Range("Q2").Select
ActiveCell.FormulaR1C1 = "SLA"
Range("Q3").Select
ActiveCell.FormulaR1C1 = "=NETWORKDAYS(RC[-1],RC[-2],)"
' Autofills based on Col A minus 1
Range("Q3").Select
Range("Q3").AutoFill Destination:=Range("Q3", Range("P3").End(xlDown).Offset(0, 1))
Range(ActiveCell, ActiveCell.End(xlDown)).Select
' Copies and Pastes Values
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
' Opens
ChDir "C:\"
Workbooks.Open Filename:="C:\Documents and Settings\ben.sharpe\Desktop\ShepherdBookedCases.xls", _
ReadOnly:=False
' Select from A2 to xldown, resize 15
Sheets("ShepherdBookedCases").Select
Range("A2", Range("A2").End(xlDown).Resize(, 17)).Select
Selection.ClearContents
' Activates Output
Windows("Output.xls").Activate
Sheets("ShepherdBookedCases").Select
' Unmerges and Deletes Row 1:1 and Selects All
Cells.Select
Selection.UnMerge
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Range("A2").Select
Range("A2", Range("A2").End(xlDown).Offset(-1, 0).Resize(, 17)).Select
Selection.Copy
' Activates ShepherdBookedCases
Windows("BookedCases.xls").Activate
Sheets("ShepherdBookedCases").Select
Range("A2").Select
ActiveSheet.Paste
ActiveWorkbook.Names.Add Name:="Data", RefersToR1C1:= _
"=OFFSET(ShepherdBookedCases!R1C1,0,0,COUNT(ShepherdBookedCases!C1),17)"
ActiveWorkbook.Names("Data").Comment = ""
Sheets("Pivot").Select
ActiveSheet.PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Data", Version:= _
xlPivotTableVersion10)
' Closes Output
Windows("Output.xls").Activate
ActiveWindow.Close
Windows("BookedCases.xls").Activate
Sheets("Pivot").Select
Range("A1").Select
Application.ScreenUpdating = True
End Sub
2007
Rich (BB code):
Sub CMGMTShepherdBookedCases()
Application.ScreenUpdating = False
' Save As Output.xls to Desktop
Application.DisplayAlerts = False
ChDir "J:\Case Management\Reporting"
ActiveWorkbook.SaveAs Filename:= _
"J:\Case Management\Reporting\Output.xls", FileFormat:= _
xlExcel8, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
Application.DisplayAlerts = True
' Adds in Appointment Column
Range("O2").Select
ActiveCell.FormulaR1C1 = "Appointment"
Range("O3").Select
ActiveCell.FormulaR1C1 = "=TEXT(RC[-14],""DD-MMM"")"
' Autofills based on Col A minus 1
Range("O3").Select
Range("O3").AutoFill Destination:=Range("O3", Range("N3").End(xlDown).Offset(0, 1))
Range(ActiveCell, ActiveCell.End(xlDown)).Select
' Adds in Instruction Column
Range("P2").Select
ActiveCell.FormulaR1C1 = "Instruction"
Range("P3").Select
ActiveCell.FormulaR1C1 = "=TEXT(RC[-3],""DD-MMM"")"
' Autofills based on Col A minus 1
Range("P3").Select
Range("P3").AutoFill Destination:=Range("P3", Range("O3").End(xlDown).Offset(0, 1))
Range(ActiveCell, ActiveCell.End(xlDown)).Select
' Adds in SLA Column
Range("Q2").Select
ActiveCell.FormulaR1C1 = "SLA"
Range("Q3").Select
ActiveCell.FormulaR1C1 = "=NETWORKDAYS(RC[-1],RC[-2],)"
' Autofills based on Col A minus 1
Range("Q3").Select
Range("Q3").AutoFill Destination:=Range("Q3", Range("P3").End(xlDown).Offset(0, 1))
Range(ActiveCell, ActiveCell.End(xlDown)).Select
' Copies and Pastes Values
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
' Opens
ChDir "C:\"
Workbooks.Open Filename:="C:\Documents and Settings\ben.sharpe\Desktop\ShepherdBookedCases.xls", _
ReadOnly:=False
' Select from A2 to xldown, resize 15
Sheets("ShepherdBookedCases").Select
Range("A2", Range("A2").End(xlDown).Resize(, 17)).Select
Selection.ClearContents
Rich (BB code):
' Activates Output
Windows("Output.xls").Activate
Sheets("ShepherdBookedCases").Select
' Unmerges and Deletes Row 1:1 and Selects All
Cells.Select
Selection.UnMerge
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Range("A2").Select
Range("A2", Range("A2").End(xlDown).Offset(-1, 0).Resize(, 17)).Select
Selection.Copy
' Activates ShepherdBookedCases
Windows("BookedCases.xls").Activate
Sheets("ShepherdBookedCases").Select
Range("A2").Select
ActiveSheet.Paste
ActiveWorkbook.Names.Add Name:="Data", RefersToR1C1:= _
"=OFFSET(ShepherdBookedCases!R1C1,0,0,COUNT(ShepherdBookedCases!C1),17)"
ActiveWorkbook.Names("Data").Comment = ""
Sheets("Pivot").Select
ActiveSheet.PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Data", Version:= _
xlPivotTableVersion10)
' Closes Output
Windows("Output.xls").Activate
ActiveWindow.Close
Windows("BookedCases.xls").Activate
Sheets("Pivot").Select
Range("A1").Select
Application.ScreenUpdating = True
End Sub