Extract text from a cell and put it in another cell

baindes

Board Regular
Joined
Dec 5, 2005
Messages
183
Hi there,

I am trying to give attributes to item descriptions that dump from a database into excel. There are several different attributes I need to pull from each item description. I need to pull size, and type and put that into another cell in another column to sort off of later. The data dumps with a description like this in each cell: 774587 cleaning product 6OZ Plastic. Another one may say: 778498 cleaning product 10OZ Glass. How do I pull the size and container type out of about 45k rows and dump that into the cell next to it? I want size in one column and type in the next column.

Regards~
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Will the size and type always be the last two "words"? If so perhaps like this
Book1
ABCD
1778498 cleaning product 10OZ Glass10OZGlass
2774587 cleaning product 6OZ Plastic6OZPlastic
3
4
5
Sheet1


Formula in C1 copied down column

=TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99))

Formula in B1 copied down column

=TRIM(RIGHT(SUBSTITUTE(TRIM(SUBSTITUTE(A1,C1,""))," ",REPT(" ",99)),99))
 
Upvote 0
hi baindes.

welcome to the board!

try this macro out. be sure to change SourceColumn and StartRow to the appropriate settings before running the program. also, please run on a copy of your file -- macros, once run, may not be undone.

hope this helps.
ben.

Code:
Sub SplitLastTwo()

Dim StartRow As Long, SourceColumn As Integer
Dim SourceRange As Range, OutputRange1 As Range, OutputRange2 As Range
Dim SourceArray(), OutputArray1(), OutputArray2()

Dim i As Long

StartRow = 2 '<-- Change this to the first row of your dataset
SourceColumn = 3 '<-- Change this to the column containing the text to break apart

Application.ScreenUpdating = False

Set SourceRange = Range(Cells(StartRow, SourceColumn), Cells(Rows.Count, SourceColumn).End(xlUp))

SourceArray = SourceRange
ReDim OutputArray1(LBound(SourceArray) To UBound(SourceArray), 1 To 1)
ReDim OutputArray2(LBound(SourceArray) To UBound(SourceArray), 1 To 1)
For i = LBound(SourceArray) To UBound(SourceArray)
    OutputArray1(i, 1) = Split(SourceArray(i, 1), " ")(UBound(Split(SourceArray(i, 1), " ")) - 1)
    OutputArray2(i, 1) = Split(SourceArray(i, 1), " ")(UBound(Split(SourceArray(i, 1), " ")))
Next i

SourceRange.Offset(0, 1).EntireColumn.Insert
SourceRange.Offset(0, 1).EntireColumn.Insert

Set OutputRange1 = SourceRange.Offset(0, 1)
Set OutputRange2 = SourceRange.Offset(0, 2)

OutputRange1 = OutputArray1
OutputRange2 = OutputArray2

Application.ScreenUpdating = True

End Sub
ps. there is no error checking in this, which means if you have fewer than two spaces in the cells you are trying to split, the code will error-out.
 
Upvote 0
Re your PM.....to get just the material if present

Borrowing from a formula posted by Domenic tonight..... you could try something like this
Book1
ABCDE
1
2778498 cleaning product 10OZ GlassGlassPVC
3774587 cleaning product 6OZ PlasticPlasticPlastic
4123456 wood container 12OZWoodWood
5Metal
6Glass
7
Sheet1


formula in B2 copied down column

=INDEX($D$2:$D$6,MATCH(TRUE,INDEX(ISNUMBER(SEARCH($D$2:$D$6,A2)),0),0))

where your 5 possibilities are in D2:D6
 
Upvote 0

Forum statistics

Threads
1,203,521
Messages
6,055,883
Members
444,830
Latest member
Excelsmallbusinessmom

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