Functions won't calculate without F2
Hmm. Perhaps I should have been a little more specific with the problem.
I have a range of cells containing the numbers 1-10, with 4 buttons that run
macros to hide/unhide the rows containg the odd or even numbers.
It's when I run these macros to hide 1/3/5/7/8 (displaying 2/4/6/8/10) or
hide 2/4/6/8/10 (displaying 1/3/5/7/9) that the function doesn't recalculate.
There is a SumVisibleRows function too that does the opposite of
SumHiddenRows, displaying a total for all the visible cells in the range thus:
Function SumVisibleRows(TheVisibleRange)
Dim VisibleTotal As Long
Dim VisibleCell As Range
VisibleTotal = 0
For Each VisibleCell In TheVisibleRange
If VisibleCell.EntireRow.Hidden = False Then
VisibleTotal = VisibleTotal + VisibleCell.Value
End If
Next
SumVisibleRows = VisibleTotal
Calculate
End Function
If I change the value of a visible cell in the list, SumVisibleCells
correctly calculates the new value without F2, but neither formula calculates
new totals on its own when the hide/unhide macros are run.
Should this be some sort of Worksheet_Change macro instead, and if so, can
anyone advise on the syntax for picking up changes to the hidden property of
a row?
Thanks again
Pete
"Peter Rooney" wrote:
Good morning all!
I wrote a simple function to calculate the values of all hidden cells in a
range.
It works fine, except that I have to edit the formula with [F2] and [Enter]
before it displays the correct answer - otherwise, it just displays the
result of the previous calculation.
Can anyone help, please?
Thanks in advance
Pete
Function SumHiddenRows(TheHiddenRange)
Dim HiddenTotal As Long
Dim HiddenCell As Range
HiddenTotal = 0
For Each HiddenCell In TheHiddenRange
If HiddenCell.EntireRow.Hidden = True Then
HiddenTotal = HiddenTotal + HiddenCell.Value
End If
Next
SumHiddenRows = HiddenTotal
Calculate
End Function
|