Hello
You can use this to test which punctuations are included:
Function GetPunc(str As String)
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = "\w"
If .test(str) Then _
GetPunc = .Replace((str), "")
End With
End Function
applied as follows:
Sub ShowPunc()
MsgBox GetPunc(ActiveCell.DirectPrecedents.Address(0, 0))
End Sub
I think only , and : are possible. If your precedent references another sheet (e.g. Sheet1!A1) then that refence won't be included hence exclamation mark shouldn't feature.
What do you mean 'split those cells'? Do you mean you want to return each cell noted in the address? E.g. A1:A10 - we can split to show A1 and A10, or are you wanting to show each cell within that range?
If all you want is to return each cell referenced in the string then try this:
Function GetElement(ByVal Text As String, ByVal n As Long, Optional ByVal Delimiter As String = " ")
GetElement = Split(Text & String(n - 1, Delimiter), Delimiter)(n - 1)
End Function
Function PuncCount(str As String)
With CreateObject("vbscript.regexp")
.Global = True
.Pattern = "\W"
If .test(str) Then _
PuncCount = Len(str) - Len(.Replace((str), ""))
End With
End Function
Sub SplitString()
Dim MyString As String
MyString = ActiveCell.DirectPrecedents.Address(0, 0)
For i = 1 To PuncCount(MyString) + 1
MsgBox GetElement(Replace(MyString, ":", ","), i, ",")
Next i
End Sub
This assumes that the only punctuation / delimiters are comma's and colons.