How can I check multiple columns?

PhantomOak

New Member
Joined
Apr 20, 2011
Messages
31
Right now I have this


Code:
Sub HURows() '
    BeginRow = 8
    EndRow = 18688
    ChkCol = 6
    For RowCnt = BeginRow To EndRow
        If Cells(RowCnt, ChkCol).Value = "" Then
            Cells(RowCnt, ChkCol).EntireRow.Hidden = True
        Else
            Cells(RowCnt, ChkCol).EntireRow.Hidden = False
        End If
    Next RowCnt
End Sub

I want it to check column, 3, 6, 7, 8, 13 and 17

How?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I changed it to

Code:
Sub HURows() '
    Application.ScreenUpdating = False
    BeginRow = 8
    EndRow = 18688
    ChkCol = 6
    ChkCol = 3
    ChkCol = 7
    ChkCol = 8
    ChkCol = 12
    ChkCol = 16
 
    For RowCnt = BeginRow To EndRow
        If Cells(RowCnt, ChkCol).Value = "" Then
            Cells(RowCnt, ChkCol).EntireRow.Hidden = True
        Else
            Cells(RowCnt, ChkCol).EntireRow.Hidden = False
        End If
    Next RowCnt
    Application.ScreenUpdating = True
End Sub

And it seems to work OK, but it will always hide a row that has a value such as "Site Remediation" in column 3 but no values in the other columns. Any ideas on THAT?
 
Last edited:
Upvote 0
I changed it to

Code:
Sub HURows() '
    Application.ScreenUpdating = False
    BeginRow = 8
    EndRow = 18688
    ChkCol = 6
    ChkCol = 3
    ChkCol = 7
    ChkCol = 8
    ChkCol = 12
    ChkCol = 16
 
    For RowCnt = BeginRow To EndRow
        If Cells(RowCnt, ChkCol).Value = "" Then
            Cells(RowCnt, ChkCol).EntireRow.Hidden = True
        Else
            Cells(RowCnt, ChkCol).EntireRow.Hidden = False
        End If
    Next RowCnt
    Application.ScreenUpdating = True
End Sub

And it seems to work OK, but it will always hide a row that has a value such as "Site Remediation" in column 3 but no values in the other columns. Any ideas on THAT?
Nope, it seems like it only works if all the columns have values...

Ack. Any help? :(

As I cant edit any other message...

I want to hide any row that does not have values in any of those columns, not hide rows that dont have data in all
 
Last edited:
Upvote 0
As written, the result will depend only on the values in column 16.

What is your requirement?
If any cell in columns 6,3,7,8,12, or 16 is blank, then hide the entire row (hides lots of rows)

or

Hide any row where column 6,3,7,8,12, or 16 are all blank. (hides fewer rows)

This code will do the first, hiding lots of rows
Code:
Sub HURows2() '
    Application.ScreenUpdating = False
    BeginRow = 8
    EndRow = 18688
    
Range("A8:A18688").EntireRow.Hidden = False

For Each ChkCol in Array(6, 3, 7, 8, 12, 16)
    For RowCnt = BeginRow To EndRow
        If Cells(RowCnt, ChkCol).Value = "" Then
            Cells(RowCnt, ChkCol).EntireRow.Hidden = True
        End If
    Next RowCnt
Next ChkCol
    Application.ScreenUpdating = True
End Sub
This will do the second, hiding fewer rows
Code:
Sub HURows3() '
    Application.ScreenUpdating = False
    BeginRow = 8
    EndRow = 18688
    
Range("A8:A18688").EntireRow.Hidden = False

    For RowCnt = BeginRow To EndRow
        With Cells(RowCnt, 6)
            .EntireRow.Hidden = (.Value = "")
        End With 
    Next RowCnt

For Each ChkCol in Array(3, 7, 8, 12, 16)
    For RowCnt = BeginRow To EndRow
        With Cells(RowCnt, ChkCol)
            If .Value <> "" Then
                .EntireRow.Hidden = False 
             End If
    Next RowCnt
Next ChkCol
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,459
Members
452,915
Latest member
hannnahheileen

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