We help IT Professionals succeed at work.

Error when pivot table is empty

63 Views
Last Modified: 2015-10-19
I have the following code in an excel spreadsheet.

Sub RefreshReport(control As IRibbonControl)
    Worksheets("Order Report").Activate
    ActiveSheet.PivotTables("Order Report").PivotSelect "'Item Description'[All]", _
        xlLabelOnly, True
    ActiveSheet.PivotTables("Order Report").PivotCache.Refresh
End Sub

Open in new window


The problem is, when this spreadsheet is first used, likely the pivot report would be empty.  This means when I run this code, I get an error stating, "Run-time error '1004':  The formula is not complete.  Make sure and ending square bracket ] is not missing."  I know this error is related to an empty pivot table because anytime I test it where the pivot report would show at least one line item, the error never appears.  On debug, lines 3 and 4 are highlighted.

Could anyone recommend some type of if/then statement that could check to see if the report would be empty and if YES, then maybe throw a message stating, "Report Empty"?

Please let me know if you need more information to help me solve this issue.  If it helps, the conditions for there to be a report is if in the tab called "Main" then Column Q from row 2 to 9999 must have a numerical value in it and cannot be blank.

I will apologize up front if I'm not using correct code or excel language.  I'm not very good with this stuff.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks much. Worked perfectly.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.