Code to hide rows

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I need some code to hide some rows if some cells are blank.

  • If C13 is blank, I need to hide row 25
  • if C14 is blank I need to hide row 26
  • If C15 is blank I need to hide row 27
  • If C16 is blank, I need to hide row 28

Can someone help me with the code please?
 
The cells are truly blank, there are no values, formulas or anything in them. That code you provided does the same thing.
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hmm, interesting, as both codes work fine for me !!
It's not imported data is it ??
 
Upvote 0
Would it matter that there is additional info in separate columns in the same row?
 
Upvote 0
Not sure what happened but I tried the code in post #5 again and it worked perfectly. Thanks Mike.

Just wondering if you could help me adjust the code so that for each row, 13-16, they are hidden if the corresponding cell in column C is blank please?
 
Upvote 0
Try

VBA Code:
Sub MM1()
Dim cell As Range, n As Long
n = 25
  For Each cell In Range("C13:C16")
    If cell.Value = "" Then
        Rows(cell.Row).Hidden = True
        Rows(n).Hidden = True
        n = n + 1
    End If
  Next cell
End Sub
 
Upvote 0
Thanks Michael, that works but my supervisor tells me he wants something else.

This code works, I just need to know how to combine it.
VBA Code:
Private Sub CommandButton1_Click()


Dim cell As Range, n As Long
n = 24


  For Each cell In Range("C13:C16")
    If cell.Value = "" Then Rows(n).Hidden = True
    n = n + 1
  Next cell
 
   If Range("C16") = "" Then
        Rows(28).Hidden = True
    End If
    
End Sub
 
Upvote 0
Actually, the code doesn't work. If I have nothing in the cells (C13:C16) it will hide the empty cells from the total rows but if there is something in C13:C16, it will not hide all of the total rows that have a 0 in them.
 
Upvote 0
if there is something in C13:C16, it will not hide all of the total rows that have a 0 in them.
The original request was to Hide rows if the CELLS WERE BLANK !!!
 
Upvote 0

Forum statistics

Threads
1,215,942
Messages
6,127,807
Members
449,408
Latest member
Bharathi V

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