If Selection does not contain a Number or Colon

F

Frankbelly

I'm trying to determine if the current selection contains any characters that
are not a digit or a colon

Any help is greatly appreciated

Thanks
 
J

Jean-Guy Marcil

Frankbelly was telling us:
Frankbelly nous racontait que :
I'm trying to determine if the current selection contains any
characters that are not a digit or a colon

Any help is greatly appreciated

Try something like this:

Sub CheckForDigitColon()

Dim strToCheck As String
Dim i As Long

strToCheck = Selection.Text
i = 1

Do
If Not Mid(strToCheck, i, 1) Like "#" And _
Not Mid(strToCheck, i, 1) Like ":" Then
MsgBox "There is a character that is not a digit or " _
& "a colon at position # " & i & "."
Exit Sub
End If
i = i + 1
Loop While i <= Len(strToCheck)

MsgBox "There are only digits and/or colons in the selection."

End Sub

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top