Hide row if specific number in cell

Nick70

Active Member
Joined
Aug 20, 2013
Messages
306
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have code below that hides rows which contain number 8 in column A.

I would like to amend code so that it hides rows which contain 8,9,10.11 in column A.

VBA Code:
Sub Hide2()
'Hide rows in a Range that contain Numbers in column K

Application.ScreenUpdating = False

    BeginRow = 1
    EndRow = 200
    ChkCol = 1

    For RowCnt = BeginRow To EndRow
        If Cells(RowCnt, ChkCol).Value = "8" Then
            Cells(RowCnt, ChkCol).EntireRow.Hidden = True
        End If
    Next RowCnt

Application.ScreenUpdating = True

End Sub

How do I do that?


Thanks,
Nix
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
VBA Code:
For RowCnt = BeginRow To EndRow
     Select Case Cells(RowCnt, ChkCol).Value
          Case "8", "9", "10", "11": Cells(RowCnt, ChkCol).EntireRow.Hidden = True
     End Select
Next RowCnt
caution "8" as string is different from 8 as value !!

But why don't you use autofilter ?
 
Upvote 0
Solution
Great Thanks!

This macro kicks in if a dropdown selects certain values (so more complicated)

Thanks,
Nix
:)(y)
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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