How to hide rows on another sheet with VBA?

Luke1997

New Member
Joined
Nov 1, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I'm a complete newbie at this and only found info from searching through google so any help would be appreciated. I currently have a VBA set up on "Sheet1" where if cell B5 = "No" it hides rows 6:7, if it = "Yes" it unhides them. Currently that works fine. What i would like it to do is also hide rows 27:37 on "Sheet 2" if (Sheet 1 B5) = "No". Below is currently what I have.

Public Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("B5"), Range(Target.Address)) Is Nothing Then
Select Case Target.Value
Case Is = "No": Rows("6:7").EntireRow.Hidden = True
Case Is = "Yes": Rows("6:7").EntireRow.Hidden = False


End Select
End If
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi
welcome to forum

See if this update to your code does what you want

Place in your Sheet1 code page

VBA Code:
Public Sub Worksheet_Change(ByVal Target As Range)
    Dim HideRows As Boolean
    If Not Application.Intersect(Range("B5"), Target) Is Nothing Then
     HideRows = UCase(Target.Value) = "NO"
     Rows("6:7").EntireRow.Hidden = HideRows
     Worksheets("Sheet2").Rows("27:37").EntireRow.Hidden = HideRows
    End If
End Sub

solution assumes value in B5 is changed by something other than formula

Hope Helpful

Dave
 
Upvote 0
Solution
Hi
welcome to forum

See if this update to your code does what you want

Place in your Sheet1 code page

VBA Code:
Public Sub Worksheet_Change(ByVal Target As Range)
    Dim HideRows As Boolean
    If Not Application.Intersect(Range("B5"), Target) Is Nothing Then
     HideRows = UCase(Target.Value) = "NO"
     Rows("6:7").EntireRow.Hidden = HideRows
     Worksheets("Sheet2").Rows("27:37").EntireRow.Hidden = HideRows
    End If
End Sub

solution assumes value in B5 is changed by something other than formula

Hope Helpful

Dave
Hi Dave,

That worked perfectly, thank you for your help
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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