hide/unhide blank rows with VBA

natedog

New Member
Joined
Nov 20, 2013
Messages
3
I am struggling to come up with a vba code that allows me to search column B, Rows 21:89 for blanks then hide/unhide the associated row. I would like it to be one macro so that I don't have to have two buttons on the sheet to hide/unhide.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try:

Code:
Sub test()
  Dim i As Long
  
  Application.ScreenUpdating = False
  
  For i = 21 To 89
    If IsEmpty(Cells(i, 2)) Then
      Rows(i).Hidden = True
    Else
      Rows(i).Hidden = False
    End If
  Next i
  
  Application.ScreenUpdating = True
End Sub


Tim
 
Upvote 0
Try:

Code:
Sub test()
  Dim i As Long
  
  Application.ScreenUpdating = False
  
  For i = 21 To 89
    If IsEmpty(Cells(i, 2)) Then
      Rows(i).Hidden = True
    Else
      Rows(i).Hidden = False
    End If
  Next i
  
  Application.ScreenUpdating = True
End Sub


Tim


Thanks Tim.
It works great to Hide the rows. Is there a way to click the same button to unhide the same rows?
 
Upvote 0
this should toggle them hidden \un hidden

Code:
Range("21:89").EntireRow.Hidden = Not Range("21:89").EntireRow.Hidden

hth,

Ross
 
Upvote 0
this should toggle them hidden \un hidden

Code:
Range("21:89").EntireRow.Hidden = Not Range("21:89").EntireRow.Hidden

hth,

Ross

It works to toggle all the rows but it isn't dependent on the cells in column "B" being blank.

After playing around with Tim's code, I would like to combine yours and his and include Column "A" along with Column "B".
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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