Macro won't work today?!?

  • Thread starter Thread starter Ed
  • Start date Start date
E

Ed

I have a macro in my Personal.xls that pops up an input box to get a text
string, then searches every cell of each row of the active worksheet for
that text. If the text is not found anywhere in that row, the row is hidden
and the code searches the next row.

Only today it won't work?!? The input box comes up, but the search hides
*EVERY* row - even when I can see the word I'm searching for right on the
screen!! The only thing I've done is copy this code as a whole block into
the worksheet module of another workbook. I haven't fiddled with the
original code.

So why isn't it working? Any ideas?

Ed
 
Whoops - forgot the code:

Sub SelectiveRowHide2()

Dim myTarget As String
Dim myFind As Range
Dim i As Integer
Dim rng As Range

myTarget = Application.InputBox("What text are you searching for?")
If ActiveSheet.AutoFilterMode Then
Set rng = ActiveSheet.AutoFilter.Range
Else
Set rng = Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp))
End If
Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1)
For Each Cell In rng.SpecialCells(xlVisible)
i = Cell.Row
If Not Rows(i).Hidden Then
Rows(i).Select
Set myFind = Rows(i).Find(What:=myTarget)
If myFind Is Nothing Then
Selection.EntireRow.Hidden = True
End If
End If
Next Cell
End Sub

Ed
 
Found it. Apparently, I had done a Find and checked Whole Cells only, and
Excel remembered that (stupid program!). So I modified my code to include
LookAt:=xlPart, and now it works fine.

Ed
 
Back
Top