Extract Text after last character

pto160

Active Member
Joined
Feb 1, 2009
Messages
482
Office Version
  1. 365
Platform
  1. Windows
I have a credit card statement and I am trying to extract text after the last specific character in this case "-" and before the text cash or credit card at the end. So in between - and cash or credit card at the end. The number of character "-" could vary in a text string.

Book1
AB
1What I want
2ABC Airines-10-07-22-John Smith Credit CardJohn Smith
3Taxi Town-10-05-22-Mary Ann Stewart CashMary Ann Stewart
4TH-Stores-10-07-22-Jane Ann Smith CashJane Ann Smith
5Beyond Dreams-11-08-22-Paul Smith Credit CardPaul Smith
Sheet1
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
How about for 365
Fluff.xlsm
AB
1What I want
2ABC Airines-10-07-22-John Smith Credit CardJohn Smith
3Taxi Town-10-05-22-Mary Ann Stewart CashMary Ann Stewart
4TH-Stores-10-07-22-Jane Ann Smith CashJane Ann Smith
5Beyond Dreams-11-08-22-Paul Smith Credit CardPaul Smith
Data
Cell Formulas
RangeFormula
B2:B5B2=TEXTBEFORE(TEXTAFTER(A2,"-",-1),{"credit","cash"},,1)
 
Upvote 0
Are the only two "endings" for each cell "Credit Card" and "Cash" or are there others?

Also, is this only for your XL365 or is it also for your XL2016?
 
Upvote 0
An alternative is Power Query

Book7
ABC
2Column1Column1.2.1.1
3ABC Airines-10-07-22-John Smith Credit CardJohn Smith
4Taxi Town-10-05-22-Mary Ann Stewart CashMary Ann Stewart
5TH-Stores-10-07-22-Jane Ann Smith CashJane Ann Smith
6Beyond Dreams-11-08-22-Paul Smith Credit CardPaul Smith
Sheet2


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    #"Split Column by Delimiter" = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByEachDelimiter({"-"}, QuoteStyle.Csv, true), {"Column1.1", "Column1.2"}),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Split Column by Delimiter", "Column1.2", Splitter.SplitTextByEachDelimiter({"Credit Card"}, QuoteStyle.Csv, true), {"Column1.2.1", "Column1.2.2"}),
    #"Split Column by Delimiter2" = Table.SplitColumn(#"Split Column by Delimiter1", "Column1.2.1", Splitter.SplitTextByEachDelimiter({"Cash"}, QuoteStyle.Csv, true), {"Column1.2.1.1", "Column1.2.1.2"}),
    #"Removed Other Columns" = Table.SelectColumns(#"Split Column by Delimiter2",{"Column1.2.1.1"})
in
    #"Removed Other Columns"
 
Upvote 0
Thanks so much for the XL365 and Power Query Solution. This is very helpful.
I still unfortunately have Excel 2016 on my work computer. I hope they are upgrading us soon.

Rick, the data will have cash or credit card at the end.
Is there an Excel 2016 solution?
 
Upvote 0
How about
Excel Formula:
=SUBSTITUTE(SUBSTITUTE(FILTERXML("<k><m>"&SUBSTITUTE(A2,"-","</m><m>")&"</m></k>","//m[last()]")," Credit Card","")," Cash","")
 
Upvote 0
Power query is native to XL2016. It is called Get and Transform Data and is located on the DATA Tab of the Ribbon.
 
Upvote 0
Rick, the data will have cash or credit card at the end.
Is there an Excel 2016 solution?
Give this a try...
=SUBSTITUTE(SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(A2,"-",REPT(" ",300)),300))," Credit Card","")," Cash","")
 
Upvote 0
Thanks so much to everyone. These solutions work great.:) (y)
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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