Taking the regular expression from this thread you can incorporate it in VBA if you use the Microsoft VBScript Regular Expressions 5.5. library (find it with Tools->References in the VB Editor). The code is below - crazy regex!
Option Explicit
Function IsIPv6(ByVal strIn As String) As Boolean
Dim objRegex As New RegExp
Dim strPattern As String
strPattern = "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|"
strPattern = strPattern & "([0-9a-fA-F]{1,4}:){1,7}:|"
strPattern = strPattern & "([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|"
strPattern = strPattern & "([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|"
strPattern = strPattern & "([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|"
strPattern = strPattern & "([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|"
strPattern = strPattern & "([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|"
strPattern = strPattern & "[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|"
strPattern = strPattern & ":((:[0-9a-fA-F]{1,4}){1,7}|"
strPattern = strPattern & ":)|"
strPattern = strPattern & "fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|"
strPattern = strPattern & "::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|"
strPattern = strPattern & "(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|"
strPattern = strPattern & "1{0,1}[0-9]){0,1}[0-9])|"
strPattern = strPattern & "([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|"
strPattern = strPattern & "(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|"
strPattern = strPattern & "(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))"
objRegex.Pattern = strPattern
IsIPv6 = objRegex.Test(strIn)
End Function
Sub Test()
Debug.Print IsIPv6("2001:0000:3238:DFE1:0063:0000:0000:FEFB")
Debug.Print IsIPv6("dec0::0A68:0300")
Debug.Print IsIPv6("foo")
End Sub
Put this code in a Module
and then you can use this function in a Worksheet
:
