AutoHide VBA code

gustaphson

New Member
Joined
Apr 22, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Good Afternoon,

I am completing a workbook in which I need to hide rows based on a selection in the first sheet. The following code is included in the first sheet "S1" and it works. Sheet "S2" is identical to "S1" except for the fact that cell C6 on "S2" simply refrences C6 on "S1", and C6 on "S1" is a dropdown. The code on "S2" does not work, can anyone point me in the right direction? Thanks in advance!

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Activate
If Not Application.Intersect(Range("C6"), Range(Target.Address)) Is Nothing Then
        Select Case Target.Value
        Case Is = "6.33": Rows("21").EntireRow.Hidden = False
        Case Is = "9.5": Rows("21").EntireRow.Hidden = True
        Case Is = "12.5": Rows("21").EntireRow.Hidden = True
        Case Is = "19": Rows("21").EntireRow.Hidden = True
        Case Is = "25": Rows("21").EntireRow.Hidden = True
        Case Is = "37.5": Rows("21").EntireRow.Hidden = True
        Case Is = "SMA95": Rows("21").EntireRow.Hidden = True
        Case Is = "SMA125": Rows("21").EntireRow.Hidden = True
        Case Is = "4.75": Rows("21").EntireRow.Hidden = True
                                                  
       
        End Select
End If
End Sub
 
Last edited by a moderator:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Are you trying to hide row 21 on both sheets?
 
Upvote 0
Ok how about this. It needs to go in the S1 sheet module in place of the existing code.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Not Intersect(Range("C6"), Target) Is Nothing Then
      Select Case Target.Value
      Case "6.33"
         Rows(21).Hidden = False
         Sheets("S2").Rows(21).Hidden = False
      Case Else
         Rows(21).Hidden = True
         Sheets("S2").Rows(21).Hidden = True
      End Select
   End If
End Sub
 
Upvote 0
Ok how about this. It needs to go in the S1 sheet module in place of the existing code.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Not Intersect(Range("C6"), Target) Is Nothing Then
      Select Case Target.Value
      Case "6.33"
         Rows(21).Hidden = False
         Sheets("S2").Rows(21).Hidden = False
      Case Else
         Rows(21).Hidden = True
         Sheets("S2").Rows(21).Hidden = True
      End Select
   End If
End Sub
That worked. Thanks!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,635
Messages
6,125,945
Members
449,275
Latest member
jacob_mcbride

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