View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jens Lenge Jens Lenge is offline
external usenet poster
 
Posts: 6
Default Repeated search on the same worksheet

Hi folks,

I have trouble doing repeated searches on the same worksheet. I use this
small function to find a specific value on a given worksheet:

Function Find(ByRef sheet As Worksheet, ByVal label As String) As String
Dim cell As Range
Set cell = sheet.Cells.Find(label);
If cell Is Nothing Then
Find = "(not found)"
Exit Function
End If
cell = cell.Cells(1, 2) ' one cell to the right
Find = cell.Value
End Function

I want to have the search on the entire worksheet each time the function
is called. In particular, when I call it twice with the same "sheet" and
"label" arguments, I want it to find exactly the same occurence.

However, the function does only return the first (and only) occurence of
"label" when it is called for the first time. A second call fails and
delivers "(not found)".

What the heck am I doing wrong?

Jens