![]() |
How to program a macro to hide rows with conditionnal formating
I have a table with various rows, identified, lets say, by the type of info (Requirements / Guidelines / Info). I want to program a macro (for 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 a row is inserted, the program has to be revised. I would also need a macro to automatically unhide all rows. Thanx a lot! -- Turquoise_dax ------------------------------------------------------------------------ Turquoise_dax's Profile: http://www.excelforum.com/member.php...o&userid=35185 View this thread: http://www.excelforum.com/showthread...hreadid=553626 |
How to program a macro to hide rows with conditionnal formating
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 "Turquoise_dax" wrote: I have a table with various rows, identified, lets say, by the type of info (Requirements / Guidelines / Info). I want to program a macro (for 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 a row is inserted, the program has to be revised. I would also need a macro to automatically unhide all rows. Thanx a lot! -- Turquoise_dax ------------------------------------------------------------------------ Turquoise_dax's Profile: http://www.excelforum.com/member.php...o&userid=35185 View this thread: http://www.excelforum.com/showthread...hreadid=553626 |
How to program a macro to hide rows with conditionnal formating
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? -- Turquoise_dax ------------------------------------------------------------------------ Turquoise_dax's Profile: http://www.excelforum.com/member.php...o&userid=35185 View this thread: http://www.excelforum.com/showthread...hreadid=553626 |
How to program a macro to hide rows with conditionnal formating
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? -- Turquoise_dax ------------------------------------------------------------------------ Turquoise_dax's Profile: http://www.excelforum.com/member.php...o&userid=35185 View this thread: http://www.excelforum.com/showthread...hreadid=553626 |
How to program a macro to hide rows with conditionnal formatin
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 "Turquoise_dax" wrote: 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? -- Turquoise_dax ------------------------------------------------------------------------ Turquoise_dax's Profile: http://www.excelforum.com/member.php...o&userid=35185 View this thread: http://www.excelforum.com/showthread...hreadid=553626 |
How to program a macro to hide rows with conditionnal formating
The following will enable you to limit your macro loop to only the 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 '-------------- -- DCSwearingen Getting old, but love computers. ------------------------------------------------------------------------ DCSwearingen's Profile: http://www.excelforum.com/member.php...o&userid=21506 View this thread: http://www.excelforum.com/showthread...hreadid=553626 |
All times are GMT +1. The time now is 04:54 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com