Substring extraction based on condition

Bering

Board Regular
Joined
Aug 22, 2018
Messages
186
Office Version
  1. 2016
Platform
  1. Windows
Hello,
I would need to find if any string in column T contains the word "FEES" and if so, extract the preceding word plus FEES in the adjacent column.

Example, description in T1:
999-TRANSFER: Y.REF.83237 O.REF.USERINT-MSCI SWFPRCXXXXXPRC TRANSFER OF USD 3,150.00 IN FAVOUR OF ENTITY1 MGT FEES Q2 2023

Result in cell U1:
MGT FEES
If "MGT FEES Q2 2023" was possible that would be even better.

NB, The string FEES can appear anywhere in the description and the length of it is variable.

Example 2:
999-TRANSFER: Y.REF. O.REF.USERINT-HNOL SWFPRC039XXXXXPRC TRANSFER OF USD 24.63 IN FAVOUR OF ENTITY2 VAT FEES 2022 AT A FX RATE OF .92828962 FX PAYMENT EQUIVALENT TO EUR 22.86

The expected result here should be:

VAT FEES
or
even better, VAT FEES 2022

Appreciate any suggestions, thank you!
 
Global = true means that it will match substring mulitple times
I have the habbit to write it automatically. But it is not necessary here.
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I wouldn't change it to False, I would leave the whole line out as I don't think it contributes anything to the result. I don't think anything would change. Try it.
 
Upvote 0
Well, try this. Without the global because you can only have one match.

VBA Code:
Function jec(c As String) As String
 With CreateObject("vbscript.regexp")
   .Pattern = "([A-Z]+\sFEES|TAX)([Q0-9 ]+)"
   If .test(c) Then jec = Trim(.Execute(c)(0))
 End With
End Function
 
Upvote 0
Well, try this. Without the global because you can only have one match.

VBA Code:
Function jec(c As String) As String
 With CreateObject("vbscript.regexp")
   .Pattern = "([A-Z]+\sFEES|TAX)([Q0-9 ]+)"
   If .test(c) Then jec = Trim(.Execute(c)(0))
 End With
End Function

It works perfectly. What resources would you recommend to learn this? Thank you so much.
 
Upvote 0
Great! I would start with this website

 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,219
Members
453,024
Latest member
Wingit77

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