Extract text from string

gazmoz17

Board Regular
Joined
Sep 18, 2020
Messages
158
Office Version
  1. 365
Platform
  1. Windows
Hi,

Do you have any pointers for the above please? I've tried a combination of formulas and text to columns but I need something automated to make a control from a query.

Were going to start selling prods as kits so need to check all descriptions and refs are correct, so variables are feeding into an online calc correctly.


Product CodeDescriptionProduct Code before bracketProduct code extract bracketsDescription m2Description grams "g"
CU10(450)Cure It 10m2 Roofing Kit 450g (light duty)1045010450
CU10(600)Cure It 10m2 Roofing Kit 600g (heavy duty)1060010600
Many Thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
It depends on how you want to go about doing it - are you looking for a VBA-based solution, or formula/etc-based solution?
 
Upvote 0
You could try this Regex UDF

VBA Code:
Function jec(rng As Range) As Variant
 With CreateObject("vbscript.regexp")
   .Global = True
   .Pattern = "(^|\D+)(\d+)(\()(\d+)(\))(.+)(\s\d+)(m.+)(\s\d+)(g.*)"
   jec = Split(.Replace(Join(Application.Transpose(Application.Transpose(rng))), "$2 $4$7$9"))
 End With
End Function

Use as:

Excel Formula:
=jec(A2:B2)
 
Upvote 0
I am pretty sure that this is not the answer to your problem. However, it does highlight the need to give sample data that shows the sort of variety that can occur in your data. Your two samples are very uniform.

gazmoz17.xlsm
ABCDEFG
1Product CodeDescriptionProduct Code before bracketProduct code extract bracketsDescription m2Description grams "g"
2
3CU10(450)Cure It 10m2 Roofing Kit 450g (light duty)1045010450
4CU10(600)Cure It 10m2 Roofing Kit 600g (heavy duty)1060010600
Sheet1
Cell Formulas
RangeFormula
D3:D4D3=MID(A3,3,2)
E3:E4E3=MID(A3,6,3)
F3:F4F3=MID(B3,9,2)
G3:G4G3=MID(B3,26,3)


MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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