findnext issues

M

mark kubicki

o.k., i give up; hthe findNext line is causing an error,
anny suggestions (XL2002, XP)

Public Function subHousemateUtility(name As Range)
Application.Volatile
Dim c
Dim firstAddress
Dim subtotal
With Worksheets("Tally Sheet").Range("B3:B10")
Set c = .Find(name.Value, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
subtotal = subtotal + c.Value
Set c = .FindNext(after:=c.Address)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
subHousemateUtility = c.Address
End Function

thanks in advance
mark
 
V

Vasant Nanavati

It would be nice to know what the error was!

I think you need c, not c.Address, as the After argument.
 
D

Dave Peterson

You had one more reply to your previous thread.

mark said:
o.k., i give up; hthe findNext line is causing an error,
anny suggestions (XL2002, XP)

Public Function subHousemateUtility(name As Range)
Application.Volatile
Dim c
Dim firstAddress
Dim subtotal
With Worksheets("Tally Sheet").Range("B3:B10")
Set c = .Find(name.Value, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
subtotal = subtotal + c.Value
Set c = .FindNext(after:=c.Address)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
subHousemateUtility = c.Address
End Function

thanks in advance
mark
 
T

Tom Ogilvy

According to Dave Peterson, who tested it in xl2002, FindNext does not work
in a UDF used in a worksheet in xl2002.

also, there is an error in your code

Set c = .FindNext(after:=c.Address)
should be

Set c = .FindNext(after:=c)

As written, your function returns the address of the first cell found - so
not sense doing the loop part

What are you trying to have returned by your function - I suspect it can be
done with builtin functions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top