Search and replace

bhupeshgrover

New Member
Joined
Jan 14, 2010
Messages
3
Hi, I am trying to search a text from a field and trying to copy it in next field. e.g the text appearing in A33 needs to be searched from b1:b32 and if found copy the entire text appearing in that filed to b33.

is there is any VBA availabe.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi,

If I understand correctly, a formula can do that, if interested, show a few lines of sample data.
 
Upvote 0
Thanks, here is some data


[TABLE="width: 892"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]Data 1[/TD]
[TD]Data 2[/TD]
[/TR]
[TR]
[TD]M170000150 [/TD]
[TD]M170000150/M170000308[/TD]
[/TR]
[TR]
[TD]M170000156[/TD]
[TD]M170000156/M170000415[/TD]
[/TR]
[TR]
[TD]M170000172[/TD]
[TD]M170000172/M170000389[/TD]
[/TR]
[TR]
[TD]M170000188[/TD]
[TD]M170000188[/TD]
[/TR]
[TR]
[TD]M170000194[/TD]
[TD]M170000194[/TD]
[/TR]
[TR]
[TD]M170000212[/TD]
[TD]M170000212/M170000299/MF17000313/MF17000314/MF17000315/MF17000316/MF17000317/MF17000267/M180000190/M180000191[/TD]
[/TR]
[TR]
[TD]M170000221[/TD]
[TD]M170000221[/TD]
[/TR]
[TR]
[TD]M170000226[/TD]
[TD]M170000226[/TD]
[/TR]
[TR]
[TD]M170000230[/TD]
[TD]M170000230[/TD]
[/TR]
[TR]
[TD]M170000233[/TD]
[TD]M170000233/234/M170000485-488/490-499/507to509/511/512/517/520/M180000021/30[/TD]
[/TR]
[TR]
[TD]M170000234[/TD]
[TD]M170000233/234/M170000485-488/490-499/507to509/511/512/517/520/M180000021/30[/TD]
[/TR]
[TR]
[TD]M170000236[/TD]
[TD]M170000236[/TD]
[/TR]
[TR]
[TD]M170000245[/TD]
[TD]M170000245/MF17000204/MF17000412[/TD]
[/TR]
[TR]
[TD]M170000251[/TD]
[TD]M170000251/M180000085[/TD]
[/TR]
[TR]
[TD]M170000253[/TD]
[TD]M170000253/MF17000272/MF170000268[/TD]
[/TR]
[TR]
[TD]M170000172[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]M170000172[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]MF17000313

[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
M180000190
 
Upvote 0
Thanks for sample data.

So hopefully I understand your query correctly.
In my sample below, B18 formula copied down.
Notice B16 is Not an exact match to A19, since B16 has an extra digit ( 1 ) at the end, if this Should be considered a Match, we can easily adjust the formula:


Book1
AB
1Data 1Data 2
2M170000150M170000150/M170000308
3M170000156M170000156/M170000415
4M170000172M170000172/M170000389
5M170000188M170000188
6M170000194M170000194
7M170000212M170000212/M170000299/MF17000313/MF17000314/MF17000315/MF17000316/MF17000317/MF17000267/M180000190/M180000191
8M170000221M170000221
9M170000226M170000226
10M170000230M170000230
11M170000233M170000233/234/M170000485-488/490-499/507to509/511/512/517/520/M180000021/30
12M170000234M170000233/234/M170000485-488/490-499/507to509/511/512/517/520/M180000021/30
13M170000236M170000236
14M170000245M170000245/MF17000204/MF17000412
15M170000251M170000251/M180000085
16Not a match->M1700001711
17M170000253M170000253/MF17000272/MF170000268
18M170000172M170000172/M170000389
19M170000171No Match
20M170000172M170000172/M170000389
21MF17000313M170000212/M170000299/MF17000313/MF17000314/MF17000315/MF17000316/MF17000317/MF17000267/M180000190/M180000191
22M180000190No Match
Sheet531
Cell Formulas
RangeFormula
B18=IFERROR(LOOKUP(2,1/SEARCH("/"&A18&"/","/"&B$2:B$17&"/"),B$2:B$17),"No Match")
 
Upvote 0
Just noticed there was a Trailing Space in A22 and thrown off the result, removed trailing space for correct result:


Book1
AB
1Data 1Data 2
2M170000150M170000150/M170000308
3M170000156M170000156/M170000415
4M170000172M170000172/M170000389
5M170000188M170000188
6M170000194M170000194
7M170000212M170000212/M170000299/MF17000313/MF17000314/MF17000315/MF17000316/MF17000317/MF17000267/M180000190/M180000191
8M170000221M170000221
9M170000226M170000226
10M170000230M170000230
11M170000233M170000233/234/M170000485-488/490-499/507to509/511/512/517/520/M180000021/30
12M170000234M170000233/234/M170000485-488/490-499/507to509/511/512/517/520/M180000021/30
13M170000236M170000236
14M170000245M170000245/MF17000204/MF17000412
15M170000251M170000251/M180000085
16Not a match->M1700001711
17M170000253M170000253/MF17000272/MF170000268
18M170000172M170000172/M170000389
19M170000171No Match
20M170000172M170000172/M170000389
21MF17000313M170000212/M170000299/MF17000313/MF17000314/MF17000315/MF17000316/MF17000317/MF17000267/M180000190/M180000191
22M180000190M170000212/M170000299/MF17000313/MF17000314/MF17000315/MF17000316/MF17000317/MF17000267/M180000190/M180000191
Sheet531
Cell Formulas
RangeFormula
B18=IFERROR(LOOKUP(2,1/SEARCH("/"&A18&"/","/"&B$2:B$17&"/"),B$2:B$17),"No Match")
 
Upvote 0
You're welcome.

The formula searches the string in Ax within Column Bx:Bx, adding a slash fore and aft of Ax and Bx:Bx to avoid incorrect matches as in my sample A19 and B16, when a match is found, return that match in Bx:Bx, if more than 1 match is found, will return the Last match in Bx:Bx, otherwise, No Match.

However, looking at your sample data further, if your Ax value is say, M170000485 or M170000486, where your B11 and B12 is M170000485-488, it will produce "No Match".
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top