Hide row if cell is blank

Littlemalky

Board Regular
Joined
Jan 14, 2011
Messages
223
I have a range("D35:D44"), and if any of those cells do not contain a value in them, then I need the entire row to be hidden, so that only the cells in that range are shown. All the code I've found is for a specific value it seems, rather than a blank cell.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try this


Code:
Sub Hiderows()
Dim c As Range
For Each c In Range("D35:D44")
    c.EntireRow.Hidden = c.Value = ""
Next c
End Sub
 
Upvote 0
Try:

Code:
Public Sub HideBlanks()
Range("D35:D44").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
End Sub
 
Upvote 0
If i wanted to implement this same technique, but delete the rows in range from D2:H, how would that work? I tried to change hidden to delete and use a LastRow reference, but it is telling object not found.
 
Upvote 0
Try

Code:
Sub DelRows()
Dim LR As Long
LR = Range("D" & Rows.Count).End(xlUp)
Range("D2:D" & LR).SpecialCells(xlCellTypeBlanks).Resize(, 5).Delete shift:=xlShiftUp
End Sub
 
Upvote 0
Hmm, doesn't seem to be doing anything. I have part numbers in column A, a description in column B, and quantities in column C, and i've done a vlookup in column D to return a value.

How about if a value exists, then delete row. If it's blank leave it alone.
 
Upvote 0
Try

Code:
Sub DelRows()
Dim LR As Long, i As Long
LR = Range("D" & Rows.Count).End(xlUp)
For i = LR To 2 Step -1
    If Range("D" & i).Value = "" Then Range("D" & i).Resize(, 5).Delete shift:=xlShiftUp
Next i
End Sub
 
Upvote 0
I changed it to this and it worked perfectly for what i need.
Code:
Private Sub DelRows2()
    Dim LR As Long, i As Long
    LR = Cells(Rows.Count, "D").End(xlUp).Row
    For i = LR To 2 Step -1
        If Range("D" & i).Value > 0 Then Range("D" & i).Resize(, 5).Delete shift:=xlShiftUp
    Next i
End Sub
Thanks for all your help!
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,879
Members
452,948
Latest member
Dupuhini

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