VBA: hide rows automatically based on cell text

TVhelo

New Member
Joined
Apr 23, 2021
Messages
2
Office Version
  1. 2016
Hi,

I am new to the VBA but would like to do simple thing with VBA: when specific cell has certain text on it, rows below are unhidden and when cell has something else those rows are hidden.
This macro should work automatically without running the macros manually.

I have tried several things but nothing seems to do the trick. Perhaps the issue is with VBA options, I do not know.

This is an example what I am trying to accomplish: When user selects Yes in cell C4 then row 6 is visible. Otherwise row 6 should be hidden.

Would be really pleased to have some assistance!

1619177484478.png


1619178024934.png



Private Sub Worksheet_Change(ByVal Target As Range)
If Range("C4").Value = "Yes" Then
Rows("6:6").EntireRow.Hidden = False
Else
Rows("6:6").EntireRow.Hidden = True

End If
End Sub
 

Attachments

  • 1619177448829.png
    1619177448829.png
    22.4 KB · Views: 18
  • 1619177894374.png
    1619177894374.png
    40 KB · Views: 18
  • 1619177952315.png
    1619177952315.png
    38.3 KB · Views: 17

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Welcome to the Board!

It looks like that you have placed this code in a standard modue ("Module1").
Event procedure code, which is code that runs automatically upon some event happening, needs to be placed in the proper workbook or worksheet module.
So you need to move this code to the "Sheet1" module. Then it should fire automatically when cells are manually updated.
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,241
Members
449,075
Latest member
staticfluids

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