Extricate strings from cells based on the non-alphanumeric char

ellison

Active Member
Joined
Aug 1, 2012
Messages
343
Office Version
  1. 365
Platform
  1. Windows
Hi, we are trying to extricate strings from cells and have been trying to create something like the below.

Col B: Text-Original: containing alpha (a-z or A-Z) numeric (0-9) and non alpha numeric characters. (Sometimes contains also is blank)
Col D: Extricate-01: up to the last non-alpha numeric character
Col E: Extricate-02: up to the 2nd last non-alpha numeric character
Col F: Extricate-03: up to the 3rd last non-alpha numeric character
etc


find-text-to-left-of-last-nonalphuanumeric-01.xlsm
ABCDEFGHIJKL
1RowText-OriginalText-V2: Tokenised a-z = L A-Z = L 0-9 = 9 rest of NonAlphaNumerics= _Extricate-01: 1st lastExtricate-02: 2nd lastExtricate-03: 3rd lastExtricate-04: 4TH lastExtricate-05: 5TH lastExtricate-06: 6th lastExtricate-07: 7th lastManual Notes (not needed, just to help explain)
22_ mix - of ch@racters!__LLL___LL_LL_LLLLLLL__ mix - of ch@racters--_ mix -_ mix _NaN characters X 7: 22, 14, 11, 8, 7, 2, 1
3312345 AND 78999999_LLL_99912345 AND12345NaN characters X 2: 10, 6, NB text contains upper and lower case
44 NB sometimes contains blanks [0]
55Text to be changedLLLL_LL_LL_LLLLLLLText to beText toTextNaN characters X 3: 11, 8, 5
66Texttobe-changedLLLLLLLL_LLLLLLLTexttobeNaN characters X 1: 9
77Extricate this ;LLLLLLLLL_LLLL__Extricate this Extricate thisExtricateNaN characters X 3: 16, 15, 10
88nononalphanumericLLLLLLLLLLLLLLLLLNaN characters: 0
Sheet1
Cell Formulas
RangeFormula
C2:C8C2=convertentry(B2)


NB we got some (amazing!) code from a mrexcel contributor that actually converts strings into:
a-z: L
A-L: L
0-9: 9
non alpha numeric: _

I've put the code below just in case it comes in handy...





Code on the "convertentry":

VBA Code:
Function ConvertEntry(ByVal myEntry As String) As String
  Dim X As Long
  For X = 1 To Len(myEntry)
    If Mid(myEntry, X) Like "[A-Za-z]*" Then
      Mid(myEntry, X) = "L"
    ElseIf Mid(myEntry, X) Like "#*" Then
      Mid(myEntry, X) = "9"
    Else
      Mid(myEntry, X) = "_"
    End If
  Next
  ConvertEntry = myEntry
End Function


Huge thanks for taking a look
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Do you consider @ to be alphanumeric?

If you do, change _d to
Excel Formula:
(_c>=97)*(_c<=122)+(_c>=65)*(_c<=90)+(_c>=48)*(_c<=57)+(_c=64)

Book1
ABCDEFGHI
1RowText-OriginalExtricate-01: 1st lastExtricate-02: 2nd lastExtricate-03: 3rd lastExtricate-04: 4TH lastExtricate-05: 5TH lastExtricate-06: 6th lastExtricate-07: 7th last
22_ mix - of ch@racters!_ mix - of ch@racters_ mix - of ch_ mix - of_ mix -_ mix _ mix_
3312345 AND 78912345 AND12345
44 
55Text to be changedText to beText toText
66Texttobe-changedTexttobe
77Extricate this ;Extricate this Extricate thisExtricate
88nononalphanumeric 
Sheet1
Cell Formulas
RangeFormula
C2:J2,C7:E7,C5:E5,C4,C6,C8,C3:D3C2=LET( _a,B2, _b,SEQUENCE(LEN(_a)), _c,CODE(MID(_a,_b,1)), _d,(_c>=97)*(_c<=122)+(_c>=65)*(_c<=90)+(_c>=48)*(_c<=57), _e,SORT(FILTER(_b,NOT(_d),""),,-1), IFERROR(TRANSPOSE(REPLACE(_a,_e,LEN(_a),"")),""))
Dynamic array formulas.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,081
Messages
6,123,016
Members
449,093
Latest member
ikke

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