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
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":
Huge thanks for taking a look
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 | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | |||
1 | Row | Text-Original | Text-V2: Tokenised a-z = L A-Z = L 0-9 = 9 rest of NonAlphaNumerics= _ | Extricate-01: 1st last | Extricate-02: 2nd last | Extricate-03: 3rd last | Extricate-04: 4TH last | Extricate-05: 5TH last | Extricate-06: 6th last | Extricate-07: 7th last | Manual Notes (not needed, just to help explain) | |||
2 | 2 | _ 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 | ||||
3 | 3 | 12345 AND 789 | 99999_LLL_999 | 12345 AND | 12345 | NaN characters X 2: 10, 6, NB text contains upper and lower case | ||||||||
4 | 4 | NB sometimes contains blanks [0] | ||||||||||||
5 | 5 | Text to be changed | LLLL_LL_LL_LLLLLLL | Text to be | Text to | Text | NaN characters X 3: 11, 8, 5 | |||||||
6 | 6 | Texttobe-changed | LLLLLLLL_LLLLLLL | Texttobe | NaN characters X 1: 9 | |||||||||
7 | 7 | Extricate this ; | LLLLLLLLL_LLLL__ | Extricate this | Extricate this | Extricate | NaN characters X 3: 16, 15, 10 | |||||||
8 | 8 | nononalphanumeric | LLLLLLLLLLLLLLLLL | NaN characters: 0 | ||||||||||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
C2:C8 | C2 | =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