jdecastro,
Welcome to the MrExcel forum.
Sample raw data in worksheet Sheet1:
Excel Workbook |
---|
|
---|
| A | B | C | D | E | F |
---|
1 | Title A | Title B | Title C | | Show rows with: | |
---|
2 | 1 | 2 | 3 | | | |
---|
3 | 2 | 2 | 3 | | | |
---|
4 | 2 | 1 | 3 | | | |
---|
5 | 3 | 3 | 3 | | | |
---|
6 | 3 | 1 | 1 | | | |
---|
7 | | | | | | |
---|
|
---|
If we enter a 1 in cell F1, we automatically get this:
Excel Workbook |
---|
|
---|
| A | B | C | D | E | F |
---|
1 | Title A | Title B | Title C | | Show rows with: | 1 |
---|
2 | 1 | 2 | 3 | | | |
---|
4 | 2 | 1 | 3 | | | |
---|
6 | 3 | 1 | 1 | | | |
---|
7 | | | | | | |
---|
|
---|
If we enter a 2 in cell F1, we automatically get this:
Excel Workbook |
---|
|
---|
| A | B | C | D | E | F |
---|
1 | Title A | Title B | Title C | | Show rows with: | 2 |
---|
2 | 1 | 2 | 3 | | | |
---|
3 | 2 | 2 | 3 | | | |
---|
4 | 2 | 1 | 3 | | | |
---|
7 | | | | | | |
---|
|
---|
If we enter a 3 in cell F1, we automatically get this:
Excel Workbook |
---|
|
---|
| A | B | C | D | E | F |
---|
1 | Title A | Title B | Title C | | Show rows with: | 3 |
---|
2 | 1 | 2 | 3 | | | |
---|
3 | 2 | 2 | 3 | | | |
---|
4 | 2 | 1 | 3 | | | |
---|
5 | 3 | 3 | 3 | | | |
---|
6 | 3 | 1 | 1 | | | |
---|
7 | | | | | | |
---|
|
---|
If we enter a 4 in cell F1, we automatically get this:
Excel Workbook |
---|
|
---|
| A | B | C | D | E | F |
---|
1 | Title A | Title B | Title C | | Show rows with: | 4 |
---|
7 | | | | | | |
---|
|
---|
If we delete what is in cell F1, we automatically get this:
Excel Workbook |
---|
|
---|
| A | B | C | D | E | F |
---|
1 | Title A | Title B | Title C | | Show rows with: | |
---|
2 | 1 | 2 | 3 | | | |
---|
3 | 2 | 2 | 3 | | | |
---|
4 | 2 | 1 | 3 | | | |
---|
5 | 3 | 3 | 3 | | | |
---|
6 | 3 | 1 | 1 | | | |
---|
7 | | | | | | |
---|
|
---|
Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).
Adding the Macro
1. Copy the below macro, by highlighting the macro code and pressing the keys
CTRL +
C
2. Open your workbook
3. Right click the sheet tab you want the code in (in this example,
Sheet1), and click on View Code. Paste the below code there (on the right pane) by pressing the keys
CTRL +
V
4. Press the keys
ALT +
Q to exit the Editor, and return to Excel
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
' hiker95, 10/23/2010, ME503884
If Intersect(Target, Range("F1")) Is Nothing Then
Exit Sub
Else
Call Test
End If
End Sub
Adding the Macro
1. Copy the below macro, by highlighting the macro code and pressing the keys
CTRL +
C
2. Open your workbook
3. Press the keys
ALT +
F11 to open the Visual Basic Editor
4. Press the keys
ALT +
I to activate the Insert menu
5. Press M to insert a Standard Module
6. Paste the code by pressing the keys
CTRL +
V
7. Press the keys
ALT +
Q to exit the Editor, and return to Excel
Code:
Option Explicit
Sub Test()
' hiker95, 10/23/2010, ME503884
Dim LR As Long, a As Long
Application.ScreenUpdating = False
With Worksheets("Sheet1")
.UsedRange.Rows.Hidden = False
If .Range("F1") = "" Then
Application.ScreenUpdating = True
MsgBox "There is no search data in cell F1 - macro terminated!"
Else
LR = .Cells(Rows.Count, 1).End(xlUp).Row
If LR > 1 Then
For a = LR To 2 Step -1
If Application.CountIf(.Range("A" & a & ":C" & a), .Range("F1")) = 0 Then .Rows(a).Hidden = True
Next a
Else
Application.ScreenUpdating = True
MsgBox "There is no raw data in column A - macro terminated!"
End If
End If
End With
End Sub
Then make changes to cell F1 in worksheet Sheet1.