Trim text in string

sprigelz

Board Regular
Joined
Jan 7, 2016
Messages
98
Office Version
  1. 365
Platform
  1. Windows
I have a text string that looks like this, Accu-Chek Aviva Plus $30 Retail Qty. 50

I am able to get the text before the $ sign very easily. I also need to be able to extract the price, and text after the price in separate cells.

Final product should look like this;
Accu-Chek Aviva Plus$30Retail Qty. 50

The main issue I am having is that the price, including the $ sign, can be between 2-4 characters long. I attempted to use =(mid(A8,find("$",A8),4)) but unfortunately that still pulled text after the price in some cases. Any help would be greatly appreciated!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
This might help

Book1
ABCDEFGH
1Accu-Chek Aviva Plus $30 Retail Qty. 50Accu-Chek Aviva Plus$30Retail Qty. 50
Sheet1
Cell Formulas
RangeFormula
F1:H1F1=CHOOSE({1,2,3},LEFT(A1,SEARCH("$",A1)-1),MID(MID(A1,SEARCH("$",A1),500),1,SEARCH(" ",MID(A1,SEARCH("$",A1),500))-1),MID(MID(A1,SEARCH("$",A1),500),SEARCH(" ",MID(A1,SEARCH("$",A1),500)),500))
Dynamic array formulas.
 
Upvote 0
Power Query:
// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Before = Table.AddColumn(Source, "Before", each Text.BeforeDelimiter([raw], " $"), type text),
    Between = Table.AddColumn(Before, "Between", each Text.BetweenDelimiters([raw], " ", " ", {3, RelativePosition.FromEnd}, 0), type text),
    After = Table.AddColumn(Between, "After", each Text.AfterDelimiter([raw], "0"), type text),
    RC = Table.RemoveColumns(After,{"raw"})
in
    RC
rawBeforeBetweenAfter
Accu-Chek Aviva Plus $30 Retail Qty. 50Accu-Chek Aviva Plus$30Retail Qty. 50
 
Upvote 0
I would use 3 separate (shorter) formulas.

20 11 05.xlsm
ABCD
1Accu-Chek Aviva Plus $30 Retail Qty. 50Accu-Chek Aviva Plus$30Retail Qty. 50
Extract Text
Cell Formulas
RangeFormula
B1B1=TRIM(LEFT(A1,FIND("$",A1)-1))
C1C1=TRIM(SUBSTITUTE(LEFT(A1,FIND(" ",A1,LEN(B1)+2)),B1,""))
D1D1=REPLACE(A1,1,FIND(" ",A1,FIND(C1,A1)),"")
 
Upvote 0
Solution
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,467
Members
448,965
Latest member
grijken

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