replacing/altering certain parts of a string

Robby87

Board Regular
Joined
May 9, 2008
Messages
128
Excel/VBA gurus:

I have a very long column of strings that looks like this:

. A
1 one num 1.23 JUL27/09
2 three num 2.34 NOV8/10
3 five num 2.59 DEC10/10
4 seven num 3.90 JAN1/11

I want to alter the first word (one, three, five..etc), based on the following reference array (which is actually much longer):

. A B
1 one fish
2 three dog
3 five cat
4 seven horse


I also want to delete the middle word "num", and alter the date so it shows up as mm/dd/yy.

Could I do this in VBA/excel somehow?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
First make a 2-column list like your reference array and name it Table using Insert|Name|Define (I used G1:H4). If your data is in A1:A4, in B1 enter:

=VLOOKUP(LEFT(A1,FIND(" ",A1)-1),Table,2,FALSE)

in C1 enter:

=RIGHT(A1,LEN(A1)-FIND("!",SUBSTITUTE(A1," ","!",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))

in D1 enter:

=SUBSTITUTE(MID(A1,FIND("num",A1)+LEN("num"),255),C1,"")

and in E1 enter:

=B1&D1&TEXT(SUBSTITUTE(RIGHT(C1,LEN(C1)-3),"/",LEFT(C1,3)),"mm/dd/yy")

Copy those four formulas down.
 
Upvote 0

Forum statistics

Threads
1,214,938
Messages
6,122,346
Members
449,080
Latest member
Armadillos

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