Modified Macro Hide Blank

JERRY89
4StarLounger
Posts: 516
Joined: 21 Feb 2016, 02:52

Modified Macro Hide Blank

Post by JERRY89 »

Dear All,

I do have a report where i cant use hide row if certain column is blank so I need to ask is there any possibility to use the macro below to hide a report if the entire row is blank.

Sub HideBlanks()
Dim Cell As Range
Application.ScreenUpdating = False
For Each Cell In Range("E2:E574")
Cell.EntireRow.Hidden = (Application.CountBlank(Cell.Resize(1, 4)) = 4)
Next Cell
Application.ScreenUpdating = True
End Sub

I have attached the file as below.

https://www.dropbox.com/s/2o5681z132r4e ... .xlsx?dl=0" onclick="window.open(this.href);return false;

User avatar
HansV
Administrator
Posts: 78674
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Modified Macro Hide Blank

Post by HansV »

Since your data are in columns A to J, try this:

Code: Select all

Sub HideBlanks()
    Dim r As Long
    Dim m As Long
    Application.ScreenUpdating = False
    m = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For r = 2 To m
        Range("A" & r).EntireRow.Hidden = _
            (Application.CountBlank(Range("A" & r).Resize(1, 10)) = 10)
    Next r
    Application.ScreenUpdating = True
End Sub
Best wishes,
Hans

JERRY89
4StarLounger
Posts: 516
Joined: 21 Feb 2016, 02:52

Re: Modified Macro Hide Blank

Post by JERRY89 »

Hi Hans,

Thanks A Lot it work perfectly..

JERRY89
4StarLounger
Posts: 516
Joined: 21 Feb 2016, 02:52

Re: Modified Macro Hide Blank

Post by JERRY89 »

Hi Hans,

May i get your advice, because i try to put some simple formula to lookup data =Sheet2!C3 in column I sheet1 and i go to Option-Advance-Change the option to not show Zero so although the result is shown blank but this Macro unable to hide the row that contain formula. Is there any alternative in this situation.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Modified Macro Hide Blank

Post by Rudi »

Try this

If column I has a formula, and guarenteed to not be blank...use:

Code: Select all

Sub HideBlanks()
    Dim r As Long
    Dim m As Long
    Application.ScreenUpdating = False
    m = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For r = 2 To m
        Range("A" & r).EntireRow.Hidden = _
            (Application.CountBlank(Range("A" & r).Resize(1, 10)) = 9)
    Next r
    Application.ScreenUpdating = True
End Sub
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

JERRY89
4StarLounger
Posts: 516
Joined: 21 Feb 2016, 02:52

Re: Modified Macro Hide Blank

Post by JERRY89 »

Hi Rudi,

Thanks for the guidance..It really solved my problem.