rjplante
Well-known Member
- Joined
- Oct 31, 2008
- Messages
- 569
- Office Version
- 365
- Platform
- Windows
I have a table listed below and I would like to add a button to the blue/maroon colored rows that would hide or unhide the rows in between the blue/maroon colored rows. I would like to have one macro that would work throughout the whole worksheet. If rows are visible, hide them and if they are hidden, show them. I have attempted to start a macro below, but I cannot get it to work. Is there a cleaner or more straightforward way to get this to work?
Thanks for the help.
Macro
Table
Thanks for the help.
Macro
VBA Code:
Sub SHOW_HIDE_ROWS()
Application.EnableEvents = False
If ActiveCell.Interior.Color = 15773696 Or ActiveCell.Interior.Color = RGB(192, 0, 0) And ActiveCell.Offset(1, 0).EntireRow.Hidden = True Then
Do Until ActiveCell.Interior.Color = 15773696 Or ActiveCell.Interior.Color = RGB(192, 0, 0)
ActiveCell.Offset(1, 0).Select
ActiveCell.EntireRow.Hidden = False
Loop
Else
Do Until ActiveCell.Interior.Color = 15773696 Or ActiveCell.Interior.Color = RGB(192, 0, 0)
ActiveCell.Offset(1, 0).Select
If ActiveCell.Interior.Color <> 15773696 Or ActiveCell.Interior.Color <> RGB(192, 0, 0) Then
ActiveCell.EntireRow.Hidden = True
End If
Loop
End If
Application.EnableEvents = True
End Sub
Table
Book1 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | |||
1 | Fruit | ||||||||||
2 | Oranges | 25 | 50 | 22 | 48 | 34 | 66 | 14 | 74 | ||
3 | Apples | 10 | 15 | 15 | 60 | 55 | 35 | 18 | 24 | ||
4 | Grapes | 15 | 5 | 97 | 48 | 46 | 88 | 23 | 27 | ||
5 | Meat | ||||||||||
6 | Bacon | 3 | 45 | 68 | 99 | 45 | 11 | 65 | 18 | ||
7 | Chicken | 10 | 15 | 15 | 60 | 55 | 35 | 18 | 24 | ||
8 | Port Roast | 66 | 58 | 41 | 16 | 54 | 88 | 97 | 38 | ||
9 | Beef Steak | 15 | 5 | 97 | 48 | 46 | 88 | 23 | 27 | ||
10 | Pot Roast | 24 | 51 | 54 | 66 | 38 | 32 | 30 | 41 | ||
11 | Breads | ||||||||||
12 | French Bread | 7 | 18 | 22 | 18 | 16 | 31 | 23 | 27 | ||
13 | Wheat bread | 10 | 15 | 15 | 60 | 55 | 35 | 18 | 24 | ||
14 | Sourdough | 15 | 5 | 97 | 48 | 46 | 88 | 23 | 27 | ||
15 | White bread | 54 | 37 | 38 | 68 | 49 | 84 | 18 | 13 | ||
16 | Rye bread | 10 | 15 | 15 | 60 | 55 | 35 | 18 | 24 | ||
17 | Multigrain | 3 | 25 | 65 | 48 | 97 | 35 | 64 | 15 | ||
18 | Lemon Poppy seed | 15 | 5 | 97 | 48 | 46 | 88 | 23 | 27 | ||
19 | Produce | ||||||||||
Sheet1 |
Cells with Conditional Formatting | ||||
---|---|---|---|---|
Cell | Condition | Cell Format | Stop If True | |
C18:I18 | Expression | =MOD(COLUMN(),2)=0 | text | NO |
C14:I14 | Expression | =MOD(COLUMN(),2)=0 | text | NO |
C9:I9 | Expression | =MOD(COLUMN(),2)=0 | text | NO |
C16:I16 | Expression | =MOD(COLUMN(),2)=0 | text | NO |
C13:I13 | Expression | =MOD(COLUMN(),2)=0 | text | NO |
C7:I7 | Expression | =MOD(COLUMN(),2)=0 | text | NO |
C12:I12,C6:I6,C2:I4,C8:I8,C15:I15,C17:I17,C10:I10 | Expression | =MOD(COLUMN(),2)=0 | text | NO |