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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
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
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,454
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.
 

Forum statistics

Threads
1,141,758
Messages
5,708,358
Members
421,566
Latest member
7Nabisco

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
Top