PeanutHead
New Member
- Joined
- Jan 29, 2021
- Messages
- 9
- Office Version
- 2016
- Platform
- Windows
Hi there! I hope someone out there can help me. I'm extremely new to VBA.
I have a sheet which has a number of yes/no dropdown boxes. Based on the results of these boxes, I'd like to hide/unhide rows. However, as the spreadsheet will have new rows added to it over time, I don't want to use exact cell references.
Instead, I have added in a hidden column containing formulae for each row based on the results of the dropdown boxes - producing a TRUE or FALSE. How can I use VBA to hide any rows containing FALSE in the hidden column? And MOST IMPORTANTLY, (because this is the thing I REALLY cannot figure out), how do I UNHIDE them if the formula changes to TRUE?
(To give you an idea of how the sheet works, if it helps to visualise it: It's a questionnaire, and each time you choose the dropdown to answer "yes", it reveals more rows with further questions. But we also want the option to go back and say "no", or change our answer and unhide/hide those sections again).
This is the code I've been working with. I can hide, but not unhide my rows!
Oh, and another added layer of complication - the spreadsheet is password protected. I've not even managed to think how that works, so any help would be *chef's kiss*
Private Sub Worksheet_Calculate()
Dim LastRow As Long, c As Range
Application.EnableEvents = False
LastRow = Cells(Cells.Rows.Count, "a").End(xlUp).Row
On Error Resume Next
For Each c In Range("a1:a" & LastRow)
If c.Value = "FALSE" Then
c.EntireRow.Hidden = True
Else
If c.Value = "TRUE" Then
c.EntireRow.Hidden = False
End If
On Error GoTo 0
Application.EnableEvents = True
End If
Next
End Sub
Any help you guys have would be madly appreciated! Thank you again - I've learnt a lot from lurking in this community!
I have a sheet which has a number of yes/no dropdown boxes. Based on the results of these boxes, I'd like to hide/unhide rows. However, as the spreadsheet will have new rows added to it over time, I don't want to use exact cell references.
Instead, I have added in a hidden column containing formulae for each row based on the results of the dropdown boxes - producing a TRUE or FALSE. How can I use VBA to hide any rows containing FALSE in the hidden column? And MOST IMPORTANTLY, (because this is the thing I REALLY cannot figure out), how do I UNHIDE them if the formula changes to TRUE?
(To give you an idea of how the sheet works, if it helps to visualise it: It's a questionnaire, and each time you choose the dropdown to answer "yes", it reveals more rows with further questions. But we also want the option to go back and say "no", or change our answer and unhide/hide those sections again).
This is the code I've been working with. I can hide, but not unhide my rows!
Oh, and another added layer of complication - the spreadsheet is password protected. I've not even managed to think how that works, so any help would be *chef's kiss*
Private Sub Worksheet_Calculate()
Dim LastRow As Long, c As Range
Application.EnableEvents = False
LastRow = Cells(Cells.Rows.Count, "a").End(xlUp).Row
On Error Resume Next
For Each c In Range("a1:a" & LastRow)
If c.Value = "FALSE" Then
c.EntireRow.Hidden = True
Else
If c.Value = "TRUE" Then
c.EntireRow.Hidden = False
End If
On Error GoTo 0
Application.EnableEvents = True
End If
Next
End Sub
Any help you guys have would be madly appreciated! Thank you again - I've learnt a lot from lurking in this community!