Hide rows that contain text

Buskopan

Board Regular
Joined
Aug 4, 2014
Messages
54
Hello! First of all thanks for useful website.

Need your help. I got spreadsheet with information in columns A to BL and In column "BK" on some rows i got message "closed" the rest within "BK" are with no text in it.

I need macro to hide the columns that contains "Closed" and something that will unhide them if required.

I will set that on the button.

Thank you in advance.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Code:
Sub Hide()
    n = Cells(Rows.Count, "BK").End(xlUp).Row
    For r = 1 To n
        If Cells(r, "BK") = "Closed" Then Rows(r).Hidden = True
    Next
End Sub
Code:
Sub Unhide()
    Rows("1:" & Rows.Count).Hidden = False
End Sub
Hope this helps,

Chris.
 
Last edited:
Upvote 0
Why not use Autofilter either with or without VBA
If you need VBA, and I think it will be quicker
Code:
Sub MM1()
    With Range("BK1")
        .AutoFilter
        .AutoFilter Field:=1, Criteria1:="<>" & "Closed"
    End With
End Sub

Then remove the filter to unhide
 
Upvote 0
Why not use Autofilter either with or without VBA
If you need VBA, and I think it will be quicker
Code:
Sub MM1()
    With Range("BK1")
        .AutoFilter
        .AutoFilter Field:=1, Criteria1:="<>" & "Closed"
    End With
End Sub

Then remove the filter to unhide
Thank you for another option to solve this. But for some reason this macro gives me the error


4jkkmw.jpg


Or I misunderstand something.
 
Upvote 0
Is there an autofilter already in use on the sheet ??
What error Msg do you get ???
I can't seem to replicate any error,....but try
Code:
Sub MM1()
    With Range("BK1")
        .AutoFilter
        .AutoFilter Field:=63, Criteria1:="<>" & "Closed"
    End With
End Sub
 
Last edited:
Upvote 0
Thank you for another option to solve this. But for some reason this macro gives me the error
I'm not sure about your error, but there are certainly some circumstances where Michael's code will give unexpected results (ie not what you have asked for).

Here is another version of an AutoFilter method that you could try.
Code:
Sub Hide_Rows()
  With Range("BK1", Range("BK" & Rows.Count).End(xlUp))
    .AutoFilter Field:=1, Criteria1:="<>Closed"
  End With
End Sub


Sub Show_Rows()
  On Error Resume Next
  ActiveSheet.ShowAllData
  On Error GoTo 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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