Pivot Table is Excel '03 Reference is not Valid

Bench

Board Regular
Joined
Aug 27, 2009
Messages
134
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

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
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
In Setting up Dynamic Range Names using the OFFSET() Function, you use the COUNTA() function, versus the Count() - REPLaCE throughout your code..
Maybe a type, but what's the "1" (in red) - this should be removed...

Hope this helps,,

=OFFSET(ShepherdBookedCases!$A$1,0,0,COUNTA(ShepherdBookedCases1!$A$1:$A$65536),17)
 
Upvote 0
Hey Thanks. I'll give it a try when i'm back at work on weds. I don't think the actual code has the phantom "1" in it but i'll certainly try the COUNTA over COUNT. Hopefully it'll solve it
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,693
Members
449,048
Latest member
81jamesacct

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top