Beautiful!
Great examples; you gave me just what I needed!
Sample Worksheet:
<table class="excel1" border="1" cellpadding="0" cellspacing="0"><tbody><tr style="height: 12pt;" valign="bottom" bgcolor="#999999" height="16"><td style="height: 12pt; width: 10pt;" align="center">
</td><td style="height: 12pt; width: 48pt;" align="center" height="16">A</td><td style="width: 48pt;" align="center">B</td><td style="width: 48pt;" align="center">C</td><td style="width: 48pt;" align="center">D</td><td style="width: 48pt;" align="center">E</td><td style="width: 48pt;" align="center">F</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt; width: 15pt;" width="64" align="center" bgcolor="#999999">1</td><td style="height: 12pt; width: 48pt;" width="64" align="center" height="16">
FALSE</td><td style="width: 48pt;" width="64">
</td><td style="width: 48pt;" width="64">
</td><td style="width: 48pt;" width="64">
</td><td style="width: 48pt;" width="64">
</td><td style="width: 48pt;" width="64">
</td></tr><tr style="height: 12pt;" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">2</td><td style="height: 12pt;" height="16">
</td><td>
</td><td>
</td><td>
</td><td>
</td><td>
</td></tr><tr style="height: 12pt;" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">3</td><td style="height: 12pt;" height="16">
</td><td>
</td><td>
</td><td>
</td><td>
</td><td>
</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">4</td><td class="excel2" style="height: 12pt;" bgcolor="#dbe5f1" height="16">
</td><td class="excel2" bgcolor="#dbe5f1">
Header</td><td class="excel2" bgcolor="#dbe5f1">
A</td><td class="excel2" bgcolor="#dbe5f1">
B</td><td class="excel2" bgcolor="#dbe5f1">
C</td><td class="excel2" bgcolor="#dbe5f1">
D</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">5</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">6</td><td style="height: 12pt;" align="center" height="16">
TRUE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">7</td><td style="height: 12pt;" align="center" height="16">FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">8</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">9</td><td style="height: 12pt;" align="center" height="16">
TRUE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">10</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">11</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">12</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr></tbody></table>
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim w As Worksheet, t As Worksheet
Dim h As Long, i As Long, j As Long, k As Long
Dim Rng As Range
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' h is the row index of the selected range (looping)
' i is the row index of first non-header row of selected range
' j is the row index of the last row of the selected range
' k is the kth member of the Range Rng
'
' Rng is the union of rows in the selected range where
' column A has the value "TRUE" <= to be hidden
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If Target.Address = "$A$1" And Target.Value = True Then
With ActiveSheet.Cells(4, 2).CurrentRegion
i = .Item(2, 1).row 'FIRST ROW OF DATA
j = .Item(.Rows.Count, .Columns.Count).row 'LAST ROW OF DATA
End With
k = 0
For h = i To j Step 1
If ActiveSheet.Cells(h, 1) = True Then
k = k + 1
If k = 1 Then
Set Rng = ActiveSheet.Cells(h, 1)
Debug.Print Rng.Address
Else
Set Rng = Union(Rng, ActiveSheet.Cells(h, 1))
Debug.Print Rng.Address
End If
End If
Next h
Rng.EntireRow.Hidden = True
ElseIf Target.Address = "$A$1" And Target.Value = False Then
ActiveSheet.Range(Cells(1, 1), Cells(Rows.Count, Columns.Count)).EntireRow.Hidden = False
End If
Application.EnableEvents = True
End Sub
My actual sheets have checkboxes in cells A1 and A5 through A(k) to set the corresponding cell in Column A as TRUE or FALSE. That way there are four conditions with three outcomes.
1. A1 TRUE & A(k) TRUE : Row A(k) Hidden
2. A1 TRUE & A(k) FALSE : Row A(k) Visible & Black Text
3. A1 FALSE & A(k) TRUE : Row A(k) Conditionally Formatted to Strike, Italic, & Grey
4 A1 FALSE & A(k) FALSE : Row A(k) Visible & Black Text
<table class="excel1" border="1" cellpadding="0" cellspacing="0"><tbody><tr style="height: 12pt;" valign="bottom" bgcolor="#999999" height="16"><td style="height: 12pt; width: 10pt;" align="center">
</td><td style="height: 12pt; width: 48pt;" align="center" height="16">A</td><td style="width: 48pt;" align="center">B</td><td style="width: 48pt;" align="center">C</td><td style="width: 48pt;" align="center">D</td><td style="width: 48pt;" align="center">E</td><td style="width: 48pt;" align="center">F</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt; width: 15pt;" width="64" align="center" bgcolor="#999999">1</td><td style="height: 12pt; width: 48pt;" width="64" align="center" height="16">
FALSE</td><td style="width: 48pt;" width="64">
</td><td style="width: 48pt;" width="64">
</td><td style="width: 48pt;" width="64">
</td><td style="width: 48pt;" width="64">
</td><td style="width: 48pt;" width="64">
</td></tr><tr style="height: 12pt;" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">2</td><td style="height: 12pt;" height="16">
</td><td>
</td><td>
</td><td>
</td><td>
</td><td>
</td></tr><tr style="height: 12pt;" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">3</td><td style="height: 12pt;" height="16">
</td><td>
</td><td>
</td><td>
</td><td>
</td><td>
</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">4</td><td class="excel2" style="height: 12pt;" bgcolor="#dbe5f1" height="16">
</td><td class="excel2" bgcolor="#dbe5f1">
Header</td><td class="excel2" bgcolor="#dbe5f1">
A</td><td class="excel2" bgcolor="#dbe5f1">
B</td><td class="excel2" bgcolor="#dbe5f1">
C</td><td class="excel2" bgcolor="#dbe5f1">
D</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">5</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">6</td><td style="height: 12pt;" align="center" height="16">
TRUE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">7</td><td style="height: 12pt;" align="center" height="16">FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">8</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">9</td><td style="height: 12pt;" align="center" height="16">
TRUE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">10</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">11</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">12</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr></tbody></table>
<table class="excel1" border="1" cellpadding="0" cellspacing="0"><tbody><tr style="height: 12pt;" valign="bottom" bgcolor="#999999" height="16"><td style="height: 12pt; width: 10pt;" align="center">
</td><td style="height: 12pt; width: 48pt;" align="center" height="16">A</td><td style="width: 48pt;" align="center">B</td><td style="width: 48pt;" align="center">C</td><td style="width: 48pt;" align="center">D</td><td style="width: 48pt;" align="center">E</td><td style="width: 48pt;" align="center">F</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt; width: 15pt;" width="64" align="center" bgcolor="#999999">1</td><td style="height: 12pt; width: 48pt;" width="64" align="center" height="16">
TRUE</td><td style="width: 48pt;" width="64">
</td><td style="width: 48pt;" width="64">
</td><td style="width: 48pt;" width="64">
</td><td style="width: 48pt;" width="64">
</td><td style="width: 48pt;" width="64">
</td></tr><tr style="height: 12pt;" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">2</td><td style="height: 12pt;" height="16">
</td><td>
</td><td>
</td><td>
</td><td>
</td><td>
</td></tr><tr style="height: 12pt;" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">3</td><td style="height: 12pt;" height="16">
</td><td>
</td><td>
</td><td>
</td><td>
</td><td>
</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">4</td><td class="excel2" style="height: 12pt;" bgcolor="#dbe5f1" height="16">
</td><td class="excel2" bgcolor="#dbe5f1">
Header</td><td class="excel2" bgcolor="#dbe5f1">
A</td><td class="excel2" bgcolor="#dbe5f1">
B</td><td class="excel2" bgcolor="#dbe5f1">
C</td><td class="excel2" bgcolor="#dbe5f1">
D</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">5</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">7</td><td style="height: 12pt;" align="center" height="16">FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">8</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">10</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">11</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr><tr style="height: 12pt;" valign="bottom" height="16"><td style="height: 12pt;" align="center" bgcolor="#999999">12</td><td style="height: 12pt;" align="center" height="16">
FALSE</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td><td>
hi</td></tr></tbody></table>
Again, Thanks so much!