Why do you want to select the cells? It is almost always better (faster running code, fewer problems) to avoid selecting cells.
If for some reason you don't want to use the AutoFilter, then you can also create a range containing them using the Find function. This is more efficient than looping through the cells.[vba]Sub FindStrings()
Dim s As String
Dim cel As Range, rg As Range, rgFound As Range
If Selection.Cells.Count > 1 Then Set rg = Selection Else Set rg = ActiveCell.EntireColumn
s = InputBox("What string do you want to find")
Set rgFound = rg.Find(s, lookat:=xlPart, MatchCase:=False)
If Not rgFound Is Nothing Then
Set cel = rgFound
Do
Set cel = rg.FindNext(cel)
If cel.Address = rgFound.Cells(1, 1).Address Then Exit Do
Set rgFound = Union(rgFound, cel)
Loop
rgFound.Select 'Don't know why you'd ever want to select cells, but here it is
End If
End Sub[/vba]Brad
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.