Extracting data based on an alphanumeric pattern

thedoveoflove

New Member
Joined
Jul 3, 2013
Messages
5
Hi All

I have a column of data that contains text such as 'as per A3', 'B4 requested' and 'as per F6 Mark' (these aren't cell references).

I'm trying to find a formula that will just strip out the 'A3', 'B4' and 'F6' element of the text. I've tried SEARCH with wildcards but it's not working, and can;t use the LEFT RIGHT or MID functions due to the inconsistent data.

Any ideas at all?

Thanks
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Press Alt+F11, copy the code into an empty module, check Microsoft VBScript Regular Expressions 5.5 option_
at Tools/References then use this as a User Defined Function in the next column
Code:
Function DeleteAddress(c As String) As String
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "\b[A-Z]+[[\d]+\b"
        If .Test(c) Then DeleteAddress = Application.Trim(.Replace(c, ""))
    End With
End Function
 
Upvote 0
I have a column of data that contains text such as 'as per A3', 'B4 requested' and 'as per F6 Mark' (these aren't cell references).

I'm trying to find a formula that will just strip out the 'A3', 'B4' and 'F6' element of the text.
Give this UDF a try...

Code:
Function GetAddress(S As String) As String
  Dim X As Long, Words() As String
  Words = Split(S)
  For X = 0 To UBound(Words)
    If Not Words(X) Like "*[!A-Z0-9]*" And Words(X) Like "*[A-Z]#*" And Not Words(X) Like "*#[A-Z]*" Then
      GetAddress = Words(X)
      Exit For
    End If
  Next
End Function

HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use GetAddress just like it was a built-in Excel function. For example,

=GetAddress(A1)
 
Upvote 0
Sorry, I misunderstood the task. Hope this can extract one or more address per cell.
Code:
Function ExtractAddress(c As String) As String
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "(\b[A-Z]+[[\d]+\b)|.+?"
        If .Test(c) Then ExtractAddress = Application.Trim(.Replace(c, "$1 "))
    End With
End Function
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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