Macro Help

Dan in Lowell

New Member
Joined
Sep 29, 2006
Messages
14
Hi,

I am very new to VBA and would like to create a macro that will read down column B for a value of 'Closed" and when it finds this value will hide the entire row and then continue reading down the column.

Can anyone help?

Thanks in Advance
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Code:
Sub HideSomeRows()
    Dim HideRange As Range, c As Range

' First Unhide any hidden rows
    Columns(2).EntireRow.Hidden = False
    
    Set HideRange = Range("B1:B" & _
    Range("B65536").End(xlUp).Row)
    
        For Each c In HideRange
            If c.Value = "Closed" Then c.EntireRow.Hidden = True
        Next c

End Sub
 
Upvote 0
This can also be done without looping by using autofilter.
(Much quicker if you have many rows.)
Code:
Sub Demo()
Dim LstRw As Long, bRng As Range
LstRw = Cells(Rows.Count, "B").End(xlUp).Row
ActiveSheet.AutoFilterMode = False
Columns("B:B").AutoFilter Field:=1, Criteria1:="Closed"
Set bRng = Range(Cells(2, "B"), Cells(LstRw, "B")).SpecialCells(xlCellTypeVisible)
ActiveSheet.AutoFilterMode = False
bRng.EntireRow.Hidden = True
End Sub
Note - there is a limit of (I think) about 8192 cells that can contain "Closed" before you run
into problems using the SpecialCells method.
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,391
Members
449,080
Latest member
Armadillos

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