hi,
i have written a UDF that uses .find to search for a value on another sheet, if it finds it, it will check a certain column to see if it has a value. if it has a value it returns the word "sampled". if it is empty it will use .findnext to find the next value and keep looping till all have been searched. i wrote a subroutine, tested it and it works. but when i use it in a UDF it sets the .findnext to Nothing instead of the next entry. the code is:
while testing it sets the objFind = .findnext(objFind) to nothing, even tho there are other entries. then it just stops and returns a #value at the loop.
any ideas?
thanks
luke
i have written a UDF that uses .find to search for a value on another sheet, if it finds it, it will check a certain column to see if it has a value. if it has a value it returns the word "sampled". if it is empty it will use .findnext to find the next value and keep looping till all have been searched. i wrote a subroutine, tested it and it works. but when i use it in a UDF it sets the .findnext to Nothing instead of the next entry. the code is:
Code:
Function FindIfSampled(ByVal strholeid As String)
Dim objFind As Object
Dim firstAddress As String
Dim intFindRow As Integer
Dim intLastRow As Integer
intLastRow = ThisWorkbook.Sheets("Sampling Work").Range("B65536").End(xlUp).Row
With ThisWorkbook.Sheets("Sampling Work").Range("B3:B" & intLastRow)
Set objFind = .Find(strholeid, LookIn:=xlValues, LookAt:=xlWhole)
If Not objFind Is Nothing Then
firstAddress = objFind.Address
Do
intFindRow = objFind.Row
If ThisWorkbook.Sheets("Sampling Work").Range("Y" & intFindRow).Value <> "" Then
FindIfSampled = "sampled"
Exit Do
Else: FindIfSampled = ""
End If
Set objFind = .FindNext(objFind)
Loop While Not objFind Is Nothing And firstAddress <> objFind.Address
End If
Set objFind = Nothing
End With
End Function
while testing it sets the objFind = .findnext(objFind) to nothing, even tho there are other entries. then it just stops and returns a #value at the loop.
any ideas?
thanks
luke