Extracting data from a field within a text

pratheesh1983

Board Regular
Joined
Aug 13, 2015
Messages
55
Office Version
  1. 365
Platform
  1. Windows
I have an excel table with a cell that contains message data, and the message data is divided into multiple fields that can be easily identified using the field ID format, i.e., "FEILD NO." Now have two requirements: first, to pull the complete data content of a specific field; and second, from the same field, to pull three words before the text (which would be mentioned in a separate cell) and three words after the text. If there are no words (or letters) before or after that specific word in the specific field, then there is no need to pull the content. Hence, to extract these two pieces of information, I am looking for a formula in Excel that could extract this information based on the information in different cells. I have provided below an example and the last two columns where I am looking for a formula, but for reference, I have provided the content that needs to be extracted. I would appreciate support in finding a formula for this. Thanks

Message DataField IDText To be searched Field Content (**FORMULA**)Surrounding words around the text
(**FORMULA**)
:OP:0213025
ABC BANK
TBK
SUBROTO
:OI:XYZYPESRXXX
AMO UNIVERSE
20-01
:B1:PKRSTDXXX
WYNE NETWORK
CHARLES BUILDING
ABC
:B2:
13976111
RAHUL
JURASIC INDUSTRIES
:PD1:SUSANA GRACIA THOMAS JOHN
7892567
56789
PD1ANASUSANA GRACIA THOMAS
7892567
56789
SUSANA GRACIA THOMAS
:OP:0213025
ABC BANK
TBK
SUBROTO
:OI:XYZYPESRXXX
AMO UNIVERSE
20-01
:B1:PKRSTDXXX
WYNE NETWORK
CHARLES BUILDING
ABC
:B2:
13976111
RAHUL
JURASIC INDUSTRIES
:PD1:SUSANA GRACIA THOMAS JOHN
7892567
56789
B2RAHUL13976111
RAHUL
JURASIC INDUSTRIES
RAHUL
JURASIC INDUSTRIES
:OP:0213025
ABC BANK
TBK
SUBROTO
:OI:XYZYPESRXXX
AMO UNIVERSE
20-01
:B1:PKRSTDXXX
WYNE NETWORK
CHARLES BUILDING
ABC
:B2:
219662341
ELLE LARA, FRANCISCO JAVIER JOHN
:PD:SUSANA GRACIA MINGUILLON
7892567
56789
B2E LARA219662341
ELLE LARA, FRANCISCO JAVIER JOHN

ELLE LARA, FRANCISCO JAVIER JOHN
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Could you use a User-Defined Function like this?

VBA Code:
Function GetField(s As String, FID As String, Txt As String, Optional TextOnly As Boolean) As String
  Dim RX As Object
 
  Set RX = CreateObject("VBScript.RegExp")
  RX.Pattern = "(:" & FID & ":)([^:]*?" & Txt & "[^:]*)(?=:|$)"
  If RX.Test(s) Then
    GetField = RX.Execute(s)(0).SubMatches(1) '& RX.Execute(s)(0).SubMatches(2)
    If TextOnly Then
      RX.Global = True
      RX.Pattern = "\d"
      GetField = Application.Trim(RX.Replace(GetField, ""))
    End If
  End If
End Function

pratheesh1983.xlsm
ABCDE
1Message DataField IDText To be searchedFieldWords
2:OP:0213025 ABC BANK TBK SUBROTO :OI:XYZYPESRXXX AMO UNIVERSE 20-01 :B1:PKRSTDXXX WYNE NETWORK CHARLES BUILDING ABC :B2: 13976111 RAHUL JURASIC INDUSTRIES :PD1:SUSANA GRACIA THOMAS JOHN 7892567 56789PD1ANASUSANA GRACIA THOMAS JOHN 7892567 56789SUSANA GRACIA THOMAS JOHN
3:OP:0213025 ABC BANK TBK SUBROTO :OI:XYZYPESRXXX AMO UNIVERSE 20-01 :B1:PKRSTDXXX WYNE NETWORK CHARLES BUILDING ABC :B2: 13976111 RAHUL JURASIC INDUSTRIES :PD1:SUSANA GRACIA THOMAS JOHN 7892567 56789B2RAHUL 13976111 RAHUL JURASIC INDUSTRIES RAHUL JURASIC INDUSTRIES
4:OP:0213025 ABC BANK TBK SUBROTO :OI:XYZYPESRXXX AMO UNIVERSE 20-01 :B1:PKRSTDXXX WYNE NETWORK CHARLES BUILDING ABC :B2: 219662341 ELLE LARA, FRANCISCO JAVIER JOHN :PD:SUSANA GRACIA MINGUILLON 7892567 56789B2E LARA 219662341 ELLE LARA, FRANCISCO JAVIER JOHN ELLE LARA, FRANCISCO JAVIER JOHN
Sheet1
Cell Formulas
RangeFormula
D2:D4D2=GetField(A2,B2,C2)
E2:E4E2=GetField(A2,B2,C2,TRUE)
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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