Ask for Data, Hide non-matches, Report, unhide with Macro


Posted by Marc Hennebery on December 08, 2000 5:06 PM

Dim cell As Range
Is it possible to modify this Macro to ask for the "info" to search for? I would like to have a prompt to the user for a name from Column D, hide all non-matching rows, produce a report, and upon completion run another or just unhide all rows.

Dim aRange As Range
Set aRange = Range(Range("D1"), Range("D65536").End(xlUp))
For Each cell In aRange
If cell.Value <> "info" Then
cell.EntireRow.Hidden = True
End If
Next cell
aRange.SpecialCells(xlCellTypeVisible).EntireRow.Copy

Posted by Celia on December 08, 2000 6:22 PM


Marc
Try this :-

Sub Hide_Rows()
Dim aRange As Range, cell As Range
Dim lookFor As String
Application.ScreenUpdating = False
Set aRange = Range(Range("D1"), Range("D65536").End(xlUp))
Do
lookFor = Application.InputBox(Prompt:="Enter the thingy in Column D to look for.")
If lookFor = "False" Then
Exit Sub
ElseIf lookFor <> "" Then
For Each cell In aRange
If cell.Value <> lookFor Then
cell.EntireRow.Hidden = True
End If
Next cell
aRange.SpecialCells(xlCellTypeVisible).EntireRow.Select
'PUT YOUR CODE FOR PRINTING (OR WHATEVER) HERE
aRange.EntireRow.Hidden = False
Exit Sub
Else
MsgBox "You did not enter any thingy."
End If
Loop
End Sub

Celia

Posted by Celia on December 10, 2000 12:08 AM

Posted by Celia on December 10, 2000 12:15 AM

Improved version

Improved version :-

Sub Hide_Rows()
Dim aRange As Range, cell As Range, C%
Dim lookFor As String
Application.ScreenUpdating = False
Set aRange = Range(Range("D1"), Range("D65536").End(xlUp))
Do
lookFor = Application.InputBox(Prompt:="Enter the thingy in Column D to look for.")
If lookFor = "False" Then
Exit Sub
ElseIf lookFor <> "" Then
For Each cell In aRange
If cell.Value = lookFor Then
C = C + 1
ElseIf cell.Value <> lookFor Then
cell.EntireRow.Hidden = True
End If
Next cell
If C = 0 Then
MsgBox "There is no match in Column D"
aRange.EntireRow.Hidden = False
Else
aRange.SpecialCells(xlCellTypeVisible).EntireRow.Select
'PUT YOUR CODE FOR PRINTING (OR WHATEVER) HERE
aRange.EntireRow.Hidden = False
Exit Sub
End If
Else
MsgBox "You did not enter any thingy."
End If
Loop
End Sub

Celia




Posted by Marc Hennebery on December 11, 2000 8:51 AM

Thanks a million again ...

Celia, it worked like a charm. I select the unhidden rows, paste them to a new worksheet, and report, then added a clear contents on the new worksheet for the next run.
I have one other question though, when I do the save of the Word Document, I am adding the date to the name of the template I am using. Is there a way to add the search string from this Macro to the name?