Problem coding NextFind
IMO you are going about this a little bit wrong. Find next is great for
looping through all of the possible values that you can find. You however are
just trying to find the value after the one you just found. You should use a
plain old fashioned find, not a findnext. Find has an argument LookAfter:=???
Set that to the value that you originally found (offset by one) and then you
are off to the races as it will start it's search just after the cell that
you found...
--
HTH...
Jim Thomlinson
"excelnut1954" wrote:
This is an attempt to execute a FindNext.
The user enters a PO# in a UserForm, and after clicking OK, UserForm13
comes up, with all the data pertaining to that PO. That works fine. I
put another button in that form to request to Find the Next Record.
with the same PO, if there is any.
That button's code if below. What I want is for the cell that
contains that next PO to be named "EditPO".
Then, I want to unload the present UserForm13 (which has the data from
the 1ts Find). Then reload UserForm13, which will show the data for the
next record.
Is there something I can do to make the Range Name Add statement below
work within
this procedure? Or, is it plain I'm not going about this correctly?
I tried playing around with different ways to reproduce the "C."
code in the line where I'm trying to name the range.
Thanks for any help you can offer.
J.O.
Private Sub CommandButton3_Click()
'Find Next Record
With Worksheets("Official List").Range("j6:j65536")
Set C = .Find(FindPOVal, LookIn:=xlValues)
If Not C Is Nothing Then
firstAddress = C.Address
Do
'C.Interior.Pattern = xlPatternGray50 (this line is from
the Help Example - left here as reference while figuring out how to
code my next command line, to name range, see next line.)
ActiveWorkbook.Names.Add Name:="EditPO",
RefersTo:=FoundCell
Unload UserForm13
UserForm13.Show
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address < firstAddress
End If
End With
End Sub
|