How to program a macro to hide rows with conditionnal formating

  • Thread starter Thread starter Turquoise_dax
  • Start date Start date
T

Turquoise_dax

I have a table with various rows, identified, lets say, by the type o
info (Requirements / Guidelines / Info). I want to program a macro (fo
a button) to hide all rows that contains "Info" in the "type" column.

I do not want to enter the number of the row in the macro, because if
row is inserted, the program has to be revised.

I would also need a macro to automatically unhide all rows.

Thanx a lot
 
One way wothout having to use a macro would be to do Data > Filter >
AutoFilter > and on column "type" choose > Custom > Does NOT contain > Info

This will then show only those rows that do not contain "info" in the "type"
column. To reverse the situation back to normal, just do Data > Filter >
AutoFilter again......it toggles back.

hth
Vaya con Dios,
Chuck, CABGx3
 
I need to use a macro, because it is to be linked to a button.

I tried this code:

ActiveSheet.Columns("B").Select
Selection.AutoFilter Field:=1, Criteria1:="info"
Selection.EntireRow.Hidden = True

but ALL rows get hidden. What is wrong
 
I need to use a macro, because it is to be linked to a button.

I tried this code:

ActiveSheet.Columns("B").Select
Selection.AutoFilter Field:=1, Criteria1:="info"
Selection.EntireRow.Hidden = True

but ALL rows get hidden. What is wrong
 
Try this one, it's a toggle on/off

Sub HideInfoRows()
Range("A2").Select
If ActiveSheet.AutoFilterMode = False Then
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="<>*info*", Operator:=xlAnd
Else
Selection.AutoFilter
End If
End Sub

hth
Vaya con Dios,
Chuck, CABGx3
 
The following will enable you to limit your macro loop to only th
active range, without having to always edit for any inserted rows.

Option Explicit
'--------------
Private Function FindLastCell()
Dim lCell As String
Range("A1").Select
lCell = ActiveCell.SpecialCells(xlLastCell).Address
FindLastCell = lCell
End Function
'--------------

Assuming you are looking for the word "Info" in column B (2)
'--------------
Sub HideRows()
Dim dSearch As String, lRow As Long, rNum As Long
Application.ScreenUpdating = False
Cells.EntireRow.Hidden = False
dSearch = "Info"
lRow = FindLastRow()
For rNum = 1 To lRow
If Cells(rNum, 2).Value = dSearch Then 'Column B is Col 2
Rows(rNum).EntireRow.Hidden = True
End If
Next
Application.ScreenUpdating = True
End Sub
'-------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top