Find macro with wildcard as part of code

E

excelnut1954

Background: Our PO system has a leading letter (M), then 6 digits. When
an order is changed, it is given a letter at the end each time. So, you
can start with a PO number M123456. If the order is changed, it
becomes M123456A If it is changed again, it becomes M1234156B. It
will be replaced with the next letter each time the order is changed.

The list I will be setting up search macros for will have PO number
that might, or might not have these trailing letters. I know the Find
feature will except wildcards, since I just tried it. But, as far as in
a macro, I don't know how to allow the wildcard.

Here's code for searches in another macro I have. The value
FindPOVal is created when the user enters the PO number in a textbox. I
tried putting FindPOVal*, and tried it with "", with no success.
I only want the wildcard at the end of the value. Can anyone help?
Thanks,
J.O.

Set rngToSearch = Sheets("Official List").Columns("J")

Set rngFound = rngToSearch.Find(What:=FindPOVal, _
LookIn:=xlValues, _
LookAt:=xlWhole)
 
T

Tom Ogilvy

Set rngFound = rngToSearch.Find(What:=FindPOVal & "?", _
LookIn:=xlValues, _
LookAt:=xlWhole)

or


Set rngFound = rngToSearch.Find(What:=FindPOVal & "*", _
LookIn:=xlValues, _
LookAt:=xlWhole)
 
E

excelnut1954

You're the best, Tom.
Thanks.
J.O.

Tom said:
Set rngFound = rngToSearch.Find(What:=FindPOVal & "?", _
LookIn:=xlValues, _
LookAt:=xlWhole)

or


Set rngFound = rngToSearch.Find(What:=FindPOVal & "*", _
LookIn:=xlValues, _
LookAt:=xlWhole)
 

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