Extract multiple orders from a cell with a large text string

makubexho

New Member
Joined
Jan 17, 2011
Messages
18
Office Version
  1. 2016
Platform
  1. Windows
Hi There,

I need to extract order numbers from a cell that contains a large text string, like in cell A1 containing “AP13215hsgyh),AP13333,)218)gsjebbjAP13376/()827)?AP13222……” AP+5 digits are all orders that I need to extract from this cell, which may contain 20 orders at a time.

Any thought?

Thanks ahead
 
Thanks for updating your profile & for the sample data.

i'd rather use these functions or formulae than VBA code that I am not familiar.
As you are using xl2016 you do not have the Textjoin function, so VBA will be your only realistic option
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
As function
VBA Code:
Function orders(r As Range)
Dim z As Object
Dim i As Long
Dim out As String
With CreateObject("VBScript.RegExp")
  .Pattern = "(AP\d+)"
  .Global = True
  out = ""
Set z = .Execute(a)
  For i = 1 To z.Count
 out = IIf(out = "", z.Item(i - 1) & ",", out & z.Item(i - 1) & ",")
  Next
orders = """" & out & "...(" & z.Count & ")" & "Orders"""
End With
End Function


Excel Formula:
=orders (A1)
 
Upvote 0
As function
VBA Code:
Function orders(r As Range)
Dim z As Object
Dim i As Long
Dim out As String
With CreateObject("VBScript.RegExp")
  .Pattern = "(AP\d+)"
  .Global = True
  out = ""
Set z = .Execute(a)
  For i = 1 To z.Count
 out = IIf(out = "", z.Item(i - 1) & ",", out & z.Item(i - 1) & ",")
  Next
orders = """" & out & "...(" & z.Count & ")" & "Orders"""
End With
End Function


=orders (A1)
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,872
Members
449,097
Latest member
dbomb1414

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