Hide Rows Which Do Not Contain Data

marka87uk

Board Regular
Joined
Mar 24, 2007
Messages
247
Hi,

I have a large spreadsheet which I wish to make easier to use.

With a macro, would it be possible to hide each row where there is no cells with data entered in columns F to R?

Thanks in advance.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try

Code:
Sub HideBl()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("F" & Rows.Count).ernd(xlUp).Row
For i = LR To 1 Step -1
    Rows(i).Hidden = WorksheetFunction.CountA(Range("F" & i).Resize(, 13)) = 0
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Sorry about the typo. It works for me. To clarify, should it hide rows where all of F:R are blank? Are the cells actually blank or could they contain spaces?
 
Upvote 0
No problem - I've just checked and some cells do contain spaces! (It must be the way the data is exported from an application.)

Would it be possible to adjust the code to also hide the rows if the cells only contain spaces?
 
Upvote 0
Got it!

I added in the following, unless you know of a better way?

Rows(i).Hidden = WorksheetFunction.CountA(Range("F" & i).Resize(, 13)) = 0
Rows(i).Hidden = Range("F" & i) = " "
 
Upvote 0
Oops sorry that doesn't work as it hides all rows where column F contains a space regardless of whether there is text in other columns...
 
Upvote 0
Maybe this

Code:
Sub HideBl()
Dim LR As Long, i As Long, j As Long
Application.ScreenUpdating = False
LR = Range("F" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    For j = 6 To 18
        If Cells(i, j).Value = " " Then Cells(i, j).ClearContents
    Next j
    Rows(i).Hidden = WorksheetFunction.CountA(Range("F" & i).Resize(, 13)) = 0
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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