I think given you're using this Function for a very specific task you would be best served altering the Function itself along the lines of:
Then use it from YTD columns ... assuming YTD columns are AC (Actual) & AD (Budget) and say as per you ex. we're in row 19
AC19: =SUM_VISIBLE_CELLS($C19:$Z19,AC$5)
AD19: =SUM_VISIBLE_CELLS($C19:$Z19,AD$5)
(where AC$5 contains Actual ... and AB$5 Budget)
Note:
VBA by default is Case Sensitive - so BUDGET <> Budget. You can make insensitive either by adding:
at the head of the Module containing the function or by coercing the strings (criteria & column header) to a common case using UCase( ) for example.
Also always worth declaring your variables (cell, Total).
On an aside you should be aware that hiding columns won't cause the Function to recalculate automatically given it's not a Volatile action (unlike hiding rows).
Bookmarks