Tallying Characters Used

S

Scot O

Is there a way to have Word tally the number of times individual characters
(letters, symbols, and numbers) are used in a selected passage?

TIA.
 
D

Doug Robbins

You may be able to use something like:

Dim i As Long, j As Long, arange As Range, Counter As Long, result As
Document
Set arange = Selection.Range
Set result = Documents.Add
For i = 65 To 255
Counter = 0
For j = 1 To arange.Characters.Count
If Asc(arange.Characters(j)) = i Then
Counter = Counter + 1
End If
Next j
result.Range.InsertAfter Chr(i) & vbTab & Counter & vbCr
Next i


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

Scot O

Thanks so much, Doug, for your help, but when I cut and paste your lines to
create a new macro, I get the message "Compile error: Expected: New or type
name."

Am I doing something wrong?
Scot ([email protected])
 
S

Stefan Blom

Backspace before "Document" in the declaration statement (which starts
with "Dim") so that it doesn't wrap to a second line and then press
SpaceBar to reinsert the space.
 
D

Doug Robbins

Probably caused by linebreaks inserted by the mail program. The following
should be all on one line:

Dim i As Long, j As Long, arange As Range, Counter As Long, result As
Document

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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