Skip to content

Instantly share code, notes, and snippets.

@NixonInnes
Created May 20, 2015 10:29
Show Gist options
  • Save NixonInnes/2c6fbeae66978e7421d0 to your computer and use it in GitHub Desktop.
Save NixonInnes/2c6fbeae66978e7421d0 to your computer and use it in GitHub Desktop.
[Excel] Convert a string into an alphabet (A) & numeric (N) map
Function ANNA_MAP(anna_text As String) As String
Dim map As String
Dim RegExp As Object
Set RegExp = CreateObject("VBScript.RegExp")
Dim aPattern As String
Dim nPattern As String
Dim cPattern As String
aPattern = "[a-zA-Z]"
nPattern = "[0-9]"
cPattern = "[^a-zA-Z0-9]"
For I = 1 To Len(anna_text)
RegExp.Pattern = aPattern
If RegExp.Test(Mid(anna_text, I, 1)) Then
map = map & "A"
End If
RegExp.Pattern = nPattern
If RegExp.Test(Mid(anna_text, I, 1)) Then
map = map & "N"
End If
RegExp.Pattern = cPattern
If RegExp.Test(Mid(anna_text, I, 1)) Then
map = map & Mid(anna_text, I, 1)
End If
Next
ANNA_MAP = map
Set RegExp = Nothing
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment