OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 855
- Office Version
- 365
- Platform
- Windows
Team Mr. Excel
I have an investments portfolio workbook. I have UDFs that I use to do roll-up values for columns in the investments data worksheet. UDFs work well except that they all give a #VALUE! error if I hide empty rows using VBA. That is, I have a sub (see below) that toggles hidden property of the empty rows in the data. Oddly, this happens if I run the sub in the portfolio worksheet OR in other worksheets that do not include the UDFs.
I found that if I go to the formula bar, "touch" an offending formula with the UDF call, then hit the green checkmark, the errors go away. So, I came up with what seems to be a klugey way to address the issue, using the line of code below, at the end of the sub that toggles rows' hidden property.
[Portfolio].Range("RollUpValues").Formula = [Portfolio].Range("RollUpValues").Formula
What might I try to fix this issue, if anything? Should I just live with the kluge-code "solution"?
I have an investments portfolio workbook. I have UDFs that I use to do roll-up values for columns in the investments data worksheet. UDFs work well except that they all give a #VALUE! error if I hide empty rows using VBA. That is, I have a sub (see below) that toggles hidden property of the empty rows in the data. Oddly, this happens if I run the sub in the portfolio worksheet OR in other worksheets that do not include the UDFs.
I found that if I go to the formula bar, "touch" an offending formula with the UDF call, then hit the green checkmark, the errors go away. So, I came up with what seems to be a klugey way to address the issue, using the line of code below, at the end of the sub that toggles rows' hidden property.
[Portfolio].Range("RollUpValues").Formula = [Portfolio].Range("RollUpValues").Formula
What might I try to fix this issue, if anything? Should I just live with the kluge-code "solution"?
VBA Code:
Option Explicit
Sub ToggleEmptyRows()
Dim oButton As Object
Dim rCell As Range
Set oButton = ActiveSheet.Buttons(Application.Caller)
Application.ScreenUpdating = False
If oButton.Caption Like "Hide*" _
Then
With ActiveSheet
' Loop all cells in the range named "Symbols" and hide unused rows.
For Each rCell In .Range("Symbols")
If rCell = "" _
Then
rCell.EntireRow.Hidden = True
Else
rCell.EntireRow.Hidden = False
End If
Next rCell
End With
oButton.Caption = "Show Empty Rows"
Else
ActiveSheet.Range("Symbols").EntireRow.Hidden = False
oButton.Caption = "Hide Empty Rows"
End If
[Portfolio].Range("RollUpValues").Formula = [Portfolio].Range("RollUpValues").Formula
End Sub