Hide rows with different values in the same column?

Olov

New Member
Joined
Jan 17, 2024
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hi. Would like some help with this.
I want rows with values B, D, I, K, R, S, or V in column E (5) to be hidden.
VBA Code:
Sub Hide_Rows_Column_5()
    Dim ws As Worksheet
    Application.ScreenUpdating = False
    Application.Calculation = xlManual
    Dim irow As Range, rngLoop As Range, lastrow As Long
    For Each ws In ThisWorkbook.Worksheets
        Select Case ws.Name
        Case "K1", "K2", "K3", "K4", "K7"
        lastrow = ws.Cells(ws.Rows.Count, "A").End(xlUp).row
            Set rngLoop = ws.Range("8:" & lastrow).Rows
            For Each irow In rngLoop
            If irow.Cells(5) = "B" Then 'or D, I, K, R, S, V
            irow.Hidden = True
            End If
            Next irow
        Case Else
        End Select
    Next ws
    Application.Calculation = xlAutomatic
    Application.ScreenUpdating = True
End Sub
I want to have B, D, I, K, R, S, V in
VBA Code:
If irow.Cells(5) = "B" Then
 
Try.
VBA Code:
Sub Hide_Rows_Column_5()
    Dim ws As Worksheet
    Application.ScreenUpdating = False
    Application.Calculation = xlManual
    Dim irow As Range, rngLoop As Range, lastrow As Long
    For Each ws In ThisWorkbook.Worksheets
        Select Case ws.Name
            Case "K1", "K2", "K3", "K4", "K7"
            lastrow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
                Set rngLoop = ws.Range("8:" & lastrow).Rows
                For Each irow In rngLoop
                    Select Case irow.Cells(5)
                        Case "B", "D", "I", "K", "R", "S", "V"
                            irow.Hidden = True
                    End Select
                Next irow
            Case Else
        End Select
    Next ws
    Application.Calculation = xlAutomatic
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
I get error 13 Incompatible types
Stops at
VBA Code:
Case "B", "D", "I", "K", "R", "S", "V"

When i remove
VBA Code:
, "K4", "K7"
it works
 
Last edited:
Upvote 0
Replace these lines
VBA Code:
If irow.Cells(5) = "B" Then 'or D, I, K, R, S, V
irow.Hidden = True
End If
By
VBA Code:
If InStr(1, "BDIKRSV", irow.Cells(5)) > 0 Then
irow.Hidden = True
End If
 
Upvote 0
I get error 13 Incompatible types
Stops at
VBA Code:
Case "B", "D", "I", "K", "R", "S", "V"

When i remove
VBA Code:
, "K4", "K7"
it works
I tried removing K4 and it worked. I have now reformatted the entire column E in the entire K4 and now it works.
 
Upvote 0

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