简体   繁体   中英

Excel 2010 Split Text From 1 Cell Macro

Ok, quick question here that I am having issues finding a solid solution too.. Let's say I have two columns; A and B. In column "A" There would be cells containing names such as "Item name AZ673" and then in column "B" there would be an ID number such as "AZ673". If I wanted to quickly remove that ID Number from each of the Names in Column A, How would I do that? Keep in mind there is no Comma or symbol between the Name and ID, just a space.. But the Columns are right by each other, and the Cells are Side by Side Containing the same ID's in both.. A macro to do this would be wonderful, Thank you in advanced for any solutions!

a simple loop throught he cells will do the trick

Set cl = [A1]
Do While cl <> ""
    cl = Trim(Replace(cl, cl.Offset(0, 1), ""))
    Set cl = cl.Offset(1, 0)
Loop

Note: if you have many rows (read 10's or 100's of thousands) to process iterating cells like this can be slow. there are many ways to speed it up if you need them

Create another column and use this formula:

=LEFT(A1,FIND(B1,A1)-1) & RIGHT(A1,LEN(A1)-FIND(B1,A1)-LEN(B1)+1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM