I have very simple VBA that hides or unhides rows that are already highlighted.
However, I need a toggle, so that the same code will hide or unhide specific rows. Also, I'd prefer to hide or unhide a named range of rows, if that's possible, rather than just give the usual column letters and row numbers.
Here's as far as I got with using simple memorized keystrokes:
_____________________________________________
Here's what someone else did, but I don't understand or need the complications with the button, or about the stuff on a different sheet.
Thanks,
Dave
However, I need a toggle, so that the same code will hide or unhide specific rows. Also, I'd prefer to hide or unhide a named range of rows, if that's possible, rather than just give the usual column letters and row numbers.
Here's as far as I got with using simple memorized keystrokes:
_____________________________________________
Sub rowsHide()
'Unprotect sheet
ActiveSheet.Unprotect
'Hide rows that are highlighted
Selection.EntireRow.Hidden = True
End Sub
_____________________________________________
_____________________________________________
Sub rowsUnhide()
'Unprotect sheet
ActiveSheet.Unprotect
'Unhide rows that are highlighted
Selection.EntireRow.Hidden = False
End Sub
_____________________________________________Here's what someone else did, but I don't understand or need the complications with the button, or about the stuff on a different sheet.
By onthegreen03
Hi - I set up a toggle button (ActiveX Controls) that hides/unhides columns, code is attached below. How would I change the code if I wanted to hide/unhide the same columns but on a different sheet? I want to keep the toggle button on the active sheet (let's call that "Sheet 1") and when pressed will hide/unhide columns on "Sheet 2". Thanks for your help!
Private Sub ToggleButton1_Click()
Dim xAddress As String
xAddress = "C:N"
If ToggleButton1.Value Then
Application.ActiveSheet.Columns(xAddress).Hidden = True
ToggleButton1.Caption = "Show Months"
Else
Application.ActiveSheet.Columns(xAddress).Hidden = False
ToggleButton1.Caption = "Hide Months"
End If
End Sub
xAddress = "C:N"
If ToggleButton1.Value Then
Application.ActiveSheet.Columns(xAddress).Hidden = True
ToggleButton1.Caption = "Show Months"
Else
Application.ActiveSheet.Columns(xAddress).Hidden = False
ToggleButton1.Caption = "Hide Months"
End If
End Sub
_____________________________________________
By the way, I'm really grateful when people write comments to explain their syntax or logic.Thanks,
Dave