Hi, Im fairly new to VBA and have trouble writing code in the most efficient way, so I want to know if there is a way to simplify this:
I have a table at the top of my sheet which has different identifiers for different portions of my dashboard, (Etc. if Verizon is checked no, Verizon portion of the dashboard hides)
I have written these all separate, and after adding a macro that adds protections to my sheet, the previous written macros aren't working.
I attempted adding lines to Unprotect and Re-Protect the worksheet before the "EntireRow.Hidden" is called, but it is still not working.
Any help appreciated! Heres my code.
I have a table at the top of my sheet which has different identifiers for different portions of my dashboard, (Etc. if Verizon is checked no, Verizon portion of the dashboard hides)
I have written these all separate, and after adding a macro that adds protections to my sheet, the previous written macros aren't working.
I attempted adding lines to Unprotect and Re-Protect the worksheet before the "EntireRow.Hidden" is called, but it is still not working.
Any help appreciated! Heres my code.
VBA Code:
Private Sub worksheet_change(ByVal Target As Range)
Set Target = Range("E5")
If Target.Value = "Yes" Then
Call CommissUnhide
End If
If Target.Value = "No" Then
Call CommissHide
End If
Set Target = Range("E6")
If Target.Value = "Yes" Then
Call OtherUnhide
End If
If Target.Value = "No" Then
Call OtherHide
End If
Set Target = Range("E7")
If Target.Value = "Yes" Then
Call ThreePLUnhide
End If
If Target.Value = "No" Then
Call ThreePLHide
End If
Set Target = Range("E8")
If Target.Value = "Yes" Then
Call HardwareUnhide
End If
If Target.Value = "No" Then
Call HardwareHide
End If
Set Target = Range("E9")
If Target.Value = "Yes" Then
Call ServicesUnhide
End If
If Target.Value = "No" Then
Call ServicesHide
End If
End Sub
Sub CommissUnhide()
ActiveSheet.UnProtect "abc"
ActiveSheet.Rows("12:16").EntireRow.Hidden = False
ActiveSheet.Protect "abc"
End Sub
Sub CommissHide()
ActiveSheet.UnProtect "abc"
ActiveSheet.Rows("12:16").EntireRow.Hidden = True
ActiveSheet.Protect "abc"
End Sub
Sub OtherUnhide()
ActiveSheet.UnProtect "abc"
ActiveSheet.Rows("17:21").EntireRow.Hidden = False
ActiveSheet.Protect "abc"
End Sub
Sub OtherHide()
ActiveSheet.UnProtect "abc"
ActiveSheet.Rows("17:21").EntireRow.Hidden = True
ActiveSheet.Protect "abc"
End Sub
Sub ThreePLUnhide()
ActiveSheet.UnProtect "abc"
ActiveSheet.Rows("22:26").EntireRow.Hidden = False
ActiveSheet.Protect "abc"
End Sub
Sub ThreePLHide()
ActiveSheet.UnProtect "abc"
ActiveSheet.Rows("22:26").EntireRow.Hidden = True
ActiveSheet.Protect "abc"
End Sub
Sub HardwareUnhide()
ActiveSheet.UnProtect "abc"
ActiveSheet.Rows("27:31").EntireRow.Hidden = False
ActiveSheet.Protect "abc"
End Sub
Sub HardwareHide()
ActiveSheet.UnProtect "abc"
ActiveSheet.Rows("27:31").EntireRow.Hidden = True
ActiveSheet.Protect "abc"
End Sub
Sub ServicesUnhide()
ActiveSheet.UnProtect "abc"
ActiveSheet.Rows("32:60").EntireRow.Hidden = False
ActiveSheet.Protect "abc"
End Sub
Sub ServicesHide()
ActiveSheet.UnProtect "abc"
ActiveSheet.Rows("32:60").EntireRow.Hidden = True
ActiveSheet.Protect "abc"
End Sub