Description :
Here's an example of a User Defined Function for extracting Alphabets and Digits from any given string.
Code :
Option Explicit
Public Function splitString(ByVal inputStr As String, ByVal outputType As Integer)
Dim i As Long
Dim numPart As String
Dim strPart As String
' if outputType = 0 then display digits
' if outputType = 1 then display Alphabets
For i = 1 To Len(inputStr)
If Asc(Mid(inputStr, i, 1)) > 47 And Asc(Mid(inputStr, i, 1)) < 58 Then
numPart = numPart & Mid(inputStr, i, 1)
ElseIf Asc(Mid(inputStr, i, 1)) > 64 And Asc(Mid(inputStr, i, 1)) < 91 Then
strPart = strPart & Mid(inputStr, i, 1)
ElseIf Asc(Mid(inputStr, i, 1)) > 96 And Asc(Mid(inputStr, i, 1)) < 123 Then
strPart = strPart & Mid(inputStr, i, 1)
End If
Next i
If outputType = 0 Then
splitString = numPart
ElseIf outputType = 1 Then
splitString = strPart
End If
End Function
input | digits | string |
sdfds3243 | 3243 | sdfds |
sefd323 | 323 | sefd |
sfd 32423 | 32423 | sfd |
fds 4323 | 4323 | fds |
f g j 6 899 9 | 68999 | fgj |
input | digits | string |
sdfds3243 | =splitString(A2,0) | =splitString(A2,1) |
Example File Link :
No comments:
Post a Comment