BetterBeef
New Member
- Joined
- Mar 18, 2010
- Messages
- 42
I have the following custom function that finds the "nth" time a particular string shows up in a range:
I want to know how I can return the string "ERROR" to the function Nth_Occurrence.
Essentially when there is an error in the function, I want to run the code below:
Nth_Occurrence = "ERROR"
Is this possible?
Code:
Public Function Nth_Occurrence(range_look As Range, find_it As String, _
occurrence As Long, offset_row As Long, offset_col As Long)
Dim lCount As Long
Dim rFound As Range
On Error GoTo Err_ERROR
Set rFound = range_look.Cells(1, 1)
For lCount = 1 To occurrence
Set rFound = range_look.Find(find_it, rFound, xlValues, xlWhole)
Next lCount
Nth_Occurrence = rFound.Offset(offset_row, offset_col)
End Function
I want to know how I can return the string "ERROR" to the function Nth_Occurrence.
Essentially when there is an error in the function, I want to run the code below:
Nth_Occurrence = "ERROR"
Is this possible?