简体   繁体   中英

Dynamic Excel Chart with Blank Sheet as Starting Point Throwing Errors

I have created a monthly expense tracker. Receipts are entered as the month progresses and Excel automatically creates running monthly totals from all pay types using formulas for each category like:

=((SUMIF($J$3:$J$58,"Computer", $I$3:$I$58))+(SUMIF($J$3:$J$58,"Computer", $F$3:$F$58))+(SUMIF($J$3:$J$58,"Computer", $E$3:$E$58)))

Those totals are kept in a spreadsheet at the bottom of each monthly receipt entry interface. Each monthly receipt entry interface generates a chart based off its totals spreadsheet. This data is then transferred to a yearly summary spreadsheet through links and generates a yearly running chart based off that. Everything is working perfectly except for one problem. Each month starts as a blank sheet. Until there is data entered the dynamic chart throws an error, specifically:

"A formula in this worksheet contains one or more invalid references."

This error occurs whenever someone views a blank chart, or when they save the workbook or Excel auto-saves it.

The chart runs off two items in the Name Manager:

CATEGORY =OFFSET(A!$B$105,0,0,A!$A$143,1)

and

TOTAL =OFFSET(A!$C$105,0,0,A!$A$143,1)

The problem is that $A$143 is 0 until the first receipt is entered and that is what is causing the error. This statement is in $A$143:

=+COUNTIF(C101:C134,">0")

This is pointing to a hidden ranked table with a bunch of VLOOKUP data in it such as:

=VLOOKUP($A105,$C$64:$E$97,2,FALSE)

This is referencing the running monthly total charts at the bottom of the receipt entry interface mentioned in my first paragraph above, which is ranked with formulas like:

=(RANK(E93,$E$64:$E$97))+COUNTIF(E$64:E92,E93)

The effect is that all expense categories with a zero value are ignored. There are many possible categories. So to list them all in each chart even if they have a zero value would produce a presentation with much visual clutter.

It would be fine as is if it were just me using the workbook. But there will be others and they will definitely be confused by the error. Any help would be appreciated. I've been reading blog posts most of the day and have yet to have that "AH HA!" moment. I've done my best to lay this all out so it is understandable while also including useful detail. Please let me know if you have any questions.

You can replace your COUNT formula with a 0 trapping condition

=MAX(1,COUNTIF(C101:C134,">0"))

It will incorrectly show 1 instead of 0, but you might just have to choose whichever is the lesser evil.

So, as hnk describes, a solution to this problem doesn't readily present itself. I thought I would share how I got around it. That way this thread isn't a useless orphan.

Instead of leaving blank dynamic charts, as mentioned above, I deleted and replaced them with a VBA trigger in each worksheet. Example:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$J$3" Then
Call A_Chart_Creation
End If

End Sub

This way when the first expense is entered for each month (during the process of which cell J3 would have to be populated) a macro, in this case A_Chart_Creation, creates the dynamic chart and from there everything is on autopilot. As the expense tracker also contains an annual summary expense log and chart I included generation of the annual chart in the macro for January. This way everything is nice and clean: no user-confusing errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM