ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using wildcards within a text box (https://www.excelbanter.com/excel-programming/289242-using-wildcards-within-text-box.html)

JENNA

Using wildcards within a text box
 
Hi all,

I have created a text box within a userform and I have the following
problem.

I wish to enter a surname into the text box, click a Find control
(that I have also placed on the userform) and search through a column
of cells in a worksheet and locate the surname that I have entered
into the text box.

For example if I enter 'Smith' into the text box, I wish for it to
locate, and stop on each 'Smith'.

After having done the above I would like to take it a step further and
use the star (*) wildcard with the search.

For example if I enter Sm* into the text box, I wish for it to locate,
and stop on each 'Smith', 'Smyth', 'Smithson' etc - that is, all the
records that start with 'Sm'.

Likewise, if I enter *ones into the text box, I wish for it to locate,
and stop on each 'Jones', 'Simones', 'Carones' etc - that is, all the
records that end with 'ones'.

Thanks again for your help

Tom Ogilvy

Using wildcards within a text box
 
Turn on the macro recorder, select your range, then do Edit=Find

put in Sm*
and click find.

Then click find next.

Turn off the macro recorder.

Highlight FindNext in the recorded macro and hit F1. Look at the code
example to see how to find all instances.

Modify you code so the What argument refers to the textbox value.

--
Regards,
Tom Ogilvy

JENNA wrote in message
om...
Hi all,

I have created a text box within a userform and I have the following
problem.

I wish to enter a surname into the text box, click a Find control
(that I have also placed on the userform) and search through a column
of cells in a worksheet and locate the surname that I have entered
into the text box.

For example if I enter 'Smith' into the text box, I wish for it to
locate, and stop on each 'Smith'.

After having done the above I would like to take it a step further and
use the star (*) wildcard with the search.

For example if I enter Sm* into the text box, I wish for it to locate,
and stop on each 'Smith', 'Smyth', 'Smithson' etc - that is, all the
records that start with 'Sm'.

Likewise, if I enter *ones into the text box, I wish for it to locate,
and stop on each 'Jones', 'Simones', 'Carones' etc - that is, all the
records that end with 'ones'.

Thanks again for your help





All times are GMT +1. The time now is 08:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com