I want to count all Commas "," that occur only in selected text after that I will use Count as Integer
to run the loop
My question is how do i Count ,
as following Image shows:
I Don't know how to use split
and ubound
. what is wrong with following code?
Sub CountComma()
Dim x As String, count As Integer, myRange As Range
Set myRange = ActiveDocument.Range(Selection.Range.Start, Selection.Range.End)
x = Split(myRange, ",")
count = UBound(x)
Debug.Print count
End Sub
A simple split will work.
B/c the array starts at zero you can take to
Ubound
number as is.EDIT: To use a
range
.To break down the code.
And if you want a single line of code than,