View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Mike Iacovou Mike Iacovou is offline
external usenet poster
 
Posts: 32
Default Find only in visible cells....

Hi all,
I made a function which returns the row number containing a search criteria.
The function is passed the search string (id) and the range to search in
(usually a column). This works fine - but I tried to modify it to only search
in visible cells if an autofilter had been applied - but it manages to find
hidden cells etc... any takers?
TIA

Function FindRecord(id As String, col As Range) As Long
Dim i As Long
Set col = col.SpecialCells(xlVisible)
col.Select
i = 0
On Error Resume Next
i = Selection.Find(what:=id, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Row
FindRecord = i
End Function