Question on FindNext vs Find

E

excelnut1954

I have a question about the FindNext coding, and how to integrate it
with my application.

The code below is what I have right now to perform a Find when the
user enters a PO number in TextBox1 of a userform in order to view a
record. The record will be on a list in a worksheet named Official
List. This works fine. It opens up another userform, and all the fields
are populated by the data from the requested record. Below that is the
Change Sub that sets the variable of Textbox1 for this purpose.
**************************************************
Private Sub CommandButton1_Click()
Worksheets("Official List").Activate

Dim FoundCell As Range
With Sheets("Official List")
Set FoundCell = .Cells.Find(What:=FindPOVal, After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

End With

If FoundCell Is Nothing Then
MsgBox "Not Found - Please try again"
Unload UserForm12
UserForm12.Show
Else
ActiveWorkbook.Names.Add Name:="EditPO", RefersTo:=FoundCell

Unload UserForm12
UserForm13.Show

End If
End Sub
****************************************
Private Sub TextBox1_Change()

FindPOVal = TextBox1.Value
End Sub
********************************

I've looked at the example of FindNext, (it's still a little
confusing) and I'm not sure if I'm suppose to use that to replace
the coding above, or should I use it in separate coding to identify
other PO numbers that might be on the list after the initial search is
completed.
In other words, should this be a 2 step process: the Find coding I have
above, then the FindNext coding.
Or should it all be in the FindNext coding? Hope this is clear enough
to understand.

Thanks,
J.O.
 
T

Tom Ogilvy

If you are looking for the value in FindPOVal, then you would not use
FindNext. A new value would constitute a new search. FindNext is when
there are multiple occurances of the same FindPOVal value in your range and
you want to find them all.

You will note that FindNext does not take an argument to specify what to
look for. It "inherits" the values already specified in the Find command.
 
E

excelnut1954

Ok. That answers my question. In the example given in Help for
FindNext, it almost looked like it was performing both routines. Next,
and FindNext.
I'll see what I can do with the example.

Thanks Tom
J.O.
 
E

excelnut1954

Thanks Tom.
I thought from the Help example that the FindNext coding would function
for both, Find, and FindNext.

So, how would I go from the Find routine, to FIndNext?
When the user is viewing a record, at what point would FindNext come
into play?
Would a message box appear if there is another PO to view?

I'm not sure if I'm painting a very good picture here
If you have an idea on how I would continue this, I would appreciate
it.

Thanks again
J.O.
 
T

Tom Ogilvy

Gather all the locations using the Find, FindNext example, then loop through
the list showing each to the user.
 

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