I have an intractable problem. There is this huge, long column at work which contains mixed strings with the following format:
ue6584
th45
hur4562243
So it is very irregular, the only regularity is that it starts with letters and ends with numbers. I need to split the strings in each cell so that:
ue6584 —> ue 6584
th45 —> th 45
hur4562243 —> hur 4562243
So the cell splits into two columns, one column containing the letters only, the other the numbers only. So far, I am thinking this is impossible to do in excel.
Can anyone help please?
Thank you in advance, Dritan
You will likely need VBA, so I have created a UDF (plus it gave me an excuse to play with RegEx).
First, add the RegEx reference to the VBEditor. See Step 1 from this post for how to do that.
Then add these to a Module in your workbook:
Function return_letters(ByVal target As Range)
Dim regEx As New RegExp
Dim pattern As String: pattern = "[0-9]"
With regEx
.Global = True
.MultiLine = False
.IgnoreCase = False
.pattern = pattern
End With
If regEx.Test(target) Then
return_letters = (regEx.Replace(target, ""))
End If
End Function
Function return_numbers(ByVal target As Range)
Dim regEx As New RegExp
Dim pattern As String: pattern = "[a-zA-Z]"
With regEx
.Global = True
.MultiLine = False
.IgnoreCase = False
.pattern = pattern
End With
If regEx.Test(target) Then
return_numbers = (regEx.Replace(target, ""))
End If
End Function
Finally, just call each function:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.