Need to pull data from the middle of the string

smalik

Board Regular
Joined
Oct 26, 2006
Messages
134
Office Version
  1. 365
Platform
  1. Windows
Is there is a simple formula that would let me pull a three letter or a four letter code from the middle of the string?

Column A shows the data dump from the system
Column B is my attempt to pull the code in a multi step process. (very inefficient way to do it.... I am sure there is a better way)
Column C is what I need (I manually typed the results for the purpose of this post)

The word "Policy" will always be the beginning of the string followed by a blank space, then "-", then blank space, then a code
Code can only be either 3 letters or 4 letters
Result column will show a blank cell if the string does not begin with the word "Policy" like in row 3 or 12-16

Any help is greatly appreciated.

1604328845884.png
 

smalik

Board Regular
Joined
Oct 26, 2006
Messages
134
Office Version
  1. 365
Platform
  1. Windows
another option

RawDataResult
Policy - AVIA - UA00014882AV18AAVIA
Policy - AVIA - UA00014882AV18AAVIA
Account - 3 Guys Beverages LLC
Policy - MGL - MLB-0000182-01MGL
Policy - MEL - RG1900078MEL
Policy - EXLI - RN1900239EXLI
Policy - CLL - MLB-0000183-01CLL
Policy- VPL - V-16206-19VPL
Policy- EXLI -RN1900291EXLI
Policy - PKGC - PK-19-040PKGC
Policy - PKGC - PK-19-040PKGC
Account - 3U Technologies, LLC
Account - 3U Technologies, LLC
Account - 3U Technologies, LLC
Account - 69th National Square Dance Convention
Account - 69th National Square Dance Convention

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Result = Table.SelectColumns(Table.AddColumn(Source, "Result", each if Text.StartsWith([RawData], "Policy") then Text.BetweenDelimiters([RawData], "- ", " -") else null),{"Result"})
in
    Result
This is helpful but I was trying to get it done without using the VBA code.

The other two feedbacks were helpful so I will try to go with one of them. However, your feedback is greatly appreciated.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,144,515
Messages
5,724,814
Members
422,579
Latest member
parsnipsnatcher

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
Top