Hide Rows using VBA

Tallulah2714

New Member
Joined
Sep 23, 2016
Messages
3
How do I write VBA code in Excel 2016 in order to have a particular set of rows within in a workbook hide if they do not contain any numerical or text information? The rows I am referring to have an "if" function in their cells that will pull data from a separate area of my workbook if certain information is pertinent to that formula. If those cells are empty, I want them to hide. If the cells then contain data, they should remain present.

Thank you!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
To hide rows use code like this:

Code:
  Rows("8:11").EntireRow.Hidden = [COLOR=#0000ff]True[/COLOR]

If you want to go through a specific set of cells to identify if the rows need to be hidden you could do it with a loop... i.e.\

Code:
[COLOR=#0000ff]Sub[/COLOR] Test()
   [COLOR=#0000ff] Dim[/COLOR] intLp [COLOR=#0000ff]As Integer
[/COLOR]
  [COLOR=#0000ff]  For[/COLOR] intLp = 2 [COLOR=#0000ff]To[/COLOR] 10
       [COLOR=#0000ff] If [/COLOR]Sheets("Sheet1").Cells(intLp, "A") = "x" [COLOR=#0000ff]Then[/COLOR]
            Rows(intLp).EntireRow.Hidden =[COLOR=#0000ff] True[/COLOR]
[COLOR=#0000ff]        End If[/COLOR]
[COLOR=#0000ff]    Next[/COLOR] intLp
[COLOR=#0000ff]End Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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