check if two cells in the same row are empty, then hide row

jimayers

Board Regular
Joined
Nov 14, 2010
Messages
99
hello - originally i was trying to see if all cells in a row were empty then hide that row, but I was getting nowhere. Now I am trying to check just two cells, "A" and "E," and if they are empty then hide that row. here is what I have:

Sub hideBLANKRows()
Application.ScreenUpdating = False
Dim i, c1, c2 As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To Lastrow
c1 = Cells(i, "A")
c2 = Cells(i, "E")
If c1 = xlnull Then
If c2 = xlnull Then Rows(i).Hidden = True
Next
Application.ScreenUpdating = True
End Sub

Thanks for any help - Jim A
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try this:
Code:
Sub Hide_Me()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row

    For i = 1 To Lastrow
        If Cells(i, 1).Value = xlnull And Cells(i, 5).Value = xlnull Then Rows(i).Hidden = True
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
If you want to check all columns for values and if all are empty try this script
Code:
Sub Hide_Me_All_Columns()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row

    For i = 1 To Lastrow
        If Application.CountA(Rows(i).EntireRow) = 0 Then Rows(i).Hidden = True
        
     Next

Application.ScreenUpdating = True
End Sub
 
Upvote 0
If you want to check all columns for values and if all are empty try this script
Code:
Sub Hide_Me_All_Columns()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row

    For i = 1 To Lastrow
        If Application.CountA(Rows(i).EntireRow) = 0 Then Rows(i).Hidden = True
        
     Next

Application.ScreenUpdating = True
End Sub

WOW...so simple too. I have been working on this for awhile. I just am having trouble with my syntax :(
Thanks - JA
 
Upvote 0
Glad I was able to help you. Come back here to Mr. Excel next time you need additional assistance.
WOW...so simple too. I have been working on this for awhile. I just am having trouble with my syntax :(
Thanks - JA
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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