I'm having a bit of trouble with some VBA code in achieving the desired outcome.
What I am trying to achieve with the example above is to, with the push of a toggle button the following will happen:
- All Rows with no data OR $0 in the most recent 3 columns (DEC, NOV, and OCT in the example) will be hidden. (Green cells).
- Rows with at least one value in the 3 most recent columns will remain visible (Blue Cells)
- Rows with all cells filled with a value above $0 will be visible (Yellow Cells).
Then, I need another toggle button to unhide everything in the event one of the hidden rows has a new charge.
BACKGROUND:
We own apartment buildings, and when the apartments are vacant, we must pay the utilities. When someone rents the apartment, we will not pay them. We want to track history and trends for when they are vacant, and when they are not vacant, we want them to be hidden to cut down on scrolling.
PROPOSED OPERATION:
In practice, we would like to see the following occur:
- Invoices received.
- One of the invoices references a hidden property.
- Manager presses "Unhide All" toggle button.
- Manager enters values.
- Manager presses "Hide Unused" toggle button.
- All rows with no values in current and previous 2 months (3 months total) will be hidden.
My VBA below does not hide the cells properly.
Private Sub ToggleButton1_Click()
If ToggleButton1 Then
MsgBox "All Rows Unhidden."
Rows("1:1000").EntireRow.Hidden = False
End If
End Sub
Private Sub ToggleButton2_Click()
If ToggleButton2 Then
Dim c As Range
Application.ScreenUpdating = False
For Each c In Me.Range("B3:B1000, C3:C1000, D3:D1000")
If c.Value = 0 Or c.Value = "" Then
c.EntireRow.Hidden = True
Else
c.EntireRow.Hidden = False
End If
Next c
Application.ScreenUpdating = True
End If
End Sub
This formula for ToggleButton2 does not work and misses values unless they are in range D3:D1000.
For Each c In Me.Range("B3:D1000")? - Our Man in BananasIf ToggleButton2since your sub is based on theClickaction. Second;Merefers to the current form not the worksheet. See This link - GMalc