Hiding/Unhiding rows depending on cell selection

VBNewbiwe83

New Member
Joined
Aug 29, 2018
Messages
11
Hi,

I am trying to hide rows 78 to 84 if cell C75 is populated with 'Hold', 'Insolvency' or 'other' and show if any other option is selected 'Plan' or 'SST' but it is hiding only row 79 and 80. Can anybody help?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(0, 0) = "C75" Then
    ActiveSheet.Unprotect "Experience"
    Select Case Target
        Case "Hold", "Insolvency", "Other": ActiveSheet.Rows("78, 79, 80, 81, 82, 83, 84").EntireRow.Hidden = True
    ActiveSheet.Protect "Experience", True, True
        End Select
        End If
End Sub

Thanks
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Give this Change event code a try...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address(0, 0) = "C75" Then
    Rows("78:84").Hidden = [OR(C75={"Hold","Insolvency"})]
  End If
End Sub
 
Upvote 0
Hi,

Thanks for replying, I am getting error Run-time error '1004 Unable to set the hidden property of range class.

Is this due to password protection?

Thanks
 
Upvote 0
Yes it is, try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address(0, 0) = "C75" Then
    Me.Unprotect "Password"
    Rows("78:84").Hidden = [OR(C75={"Hold","Insolvency"})]
    Me.Protect "Password"
  End If
End Sub
Change Password to suit
 
Upvote 0
Thanks, the only problem I have now is it hides row 78, 79 and 80 but not 81 and 84.

I have some code that autofits these rows based on a vlookup selections. Could this be causing a problem?

Code:
Private Sub Worksheet_Calculate()
    Dim sAddress As String
    On Error GoTo errHandle
    ActiveSheet.Unprotect "Experience"
    sAddress = "A19, A21, A25, A28, A34, A36, A38, A44, A47, A49, A55, A58, A60, A62, A64, A70, A77, A81, A84, A92"
    'disable change events
    Application.EnableEvents = False
    Range(sAddress).EntireRow.AutoFit
    're-enable events
    Application.EnableEvents = True
    ActiveSheet.Protect "Experience", True, True
errHandle:
'if there is an error ensure to re-enable events
Application.EnableEvents = True
End Sub

thanks
 
Upvote 0
Could this be causing a problem?
Yes it is. Whilst the code Rick supplied will hide those rows, as soon as the sheet recalculates, rows 81 & 84 will become visible again.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top