Using VBA to automatically hide/unhide entire rows

Milos

Board Regular
Joined
Aug 28, 2016
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am currently making a spreadsheet that needs to hide 30 rows when a certain condition has been met.

Does anyone know how to design a macro that can automatically hide/unhide 30 rows (rows 45 to 75) in the first specific worksheet "Sheet 1". The condition that will be met is when either a "Yes" or a "No" is entered into a specific cell (A3) or I could alternatively link it to a command button or combo box.

Thanks,
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Assuming the Cell A3 that you are talking about is also on that same sheet where the rows will be hidden/unhidden then try this.
1. Right click the sheet name tab and choose "View Code".
2. Copy and Paste the code below into the main right hand pane that opens at step 1.
3. Close the Visual Basic window & test.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Rows("45:75").Hidden = LCase(Range("A3").Value) = "yes"
End Sub
It will hide the rows if you type "Yes" (or yes, YES etc) into the cell otherwise it will unhide them.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
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