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?
 
I am sorry, I didn't explain it completely in the first place. Even if there is a 0 in them, I was just thinking that they were blank.
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Is this what you need ??
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 = "" Or cell.Value = 0 Then Rows(n).Hidden = True
    n = n + 1
  Next cell
 
   If Range("C16") = "" Or Range("C16") = 0 Then
        Rows(28).Hidden = True
    End If
End Sub
 
Upvote 0
That's perfect, thanks Michael, sorry to be a pain ;)
 
Upvote 0
That's ok mate...but you should be able to write these type of codes on your own now..?
 
Upvote 0
If all the cells in range C13:C16 are blank, the rows will all hide but if there are some values in some of the cells, the correct row won't hide.
 
Upvote 0
Sorry Michael, I forgot I can write some code myself now. I just need some ideas as for how to start the code, as in what syntax to use as I am not good with determining the method to use.
 
Upvote 0
So is this the part that is causing the issue ??
VBA Code:
If Range("C16") = "" Or Range("C16") = 0 Then  Rows(28).Hidden = True
Does it need to loop like the other section ??
 
Upvote 0
I had a closer look at it and I worked it out myself. Thanks for reminding me that I can code now Michael ;)
 
Upvote 0
Excellent....good to hear you got it sorted...?
 
Upvote 0
Not sure what has happened Michael but this code now only hides row 25, even if all cells in the range C13 to C16 are blank.

VBA Code:
Dim cell As Range, n As Long
n = 25
  For Each cell In Range("C13:C16")
    If cell.Value = "" Or cell.Value = 0 Then Rows(n).Hidden = True
    n = n + 1
  Next cell
 
Upvote 0

Forum statistics

Threads
1,215,945
Messages
6,127,840
Members
449,411
Latest member
adunn_23

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