Hide rows using VBA based on cell value

Analyst77

New Member
Joined
Apr 24, 2015
Messages
9
Hi all,

I am trying to hide a row in my "Overview" tab based on a cell value in my "Data" tab. So if cell B8 in my "Data" tab equals "Yes" then I want to hide rows 15 and 16 on my "Overview tab". I'm still fairly new to VBA. Below is what i came up with so far. Any help would be greatly appreciated.

Thanks!

Code:
Sub Hiderows()


Sheets("Data").Select


If Target.Address = "$B$8" Then


If Target.Value = "Yes" Then Sheets("Overview").Select Rows("15:16").EntireRow.Hidden = True


If Target.Value = "No" Then Sheets("Overview").Select Rows("15:16").EntireRow.Hidden = False


End If
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try this:

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet named "Data" tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B8")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Value = "Yes" Then Sheets("Overview").Rows("15:16").Hidden = True
If Target.Value = "No" Then Sheets("Overview").Rows("15:16").Hidden = False
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,867
Members
449,053
Latest member
Mesh

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