how do i count unique items in word table?

P

PaulM

I have a software test report template, in word, that includes the severity
of the issue in a column on a table (values being A,B,C or D). Ideally I
would need a count of the A's and B's found within this table.
 
C

Cooz

Dear Paul,

You cannot do this in Word. I suggest you replace the table by an Excel
table - it is a piece of cake in Excel. The Standard toolbar has a button
(with a table and the Excel icon) that allows you to do so.

Succes,
Cooz
 
H

Helmut Weber

Hi Paul,

want a programmatic solution?

Ask in ..public.word.vba.general

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
P

PaulM

Excel certainly has the functionality to sum and count better than word,
however the test reports need to be in a word format (legacy reasons).
Another option is to store the info in Access and export to Word (Not an easy
process for temp testers).

I'm not positive about 'cannot'; theres always a way, it just depends on how
messy the way is!
 
D

Doug Robbins - Word MVP

The following will sum the occurences of the A's, B's, C's and D's in the
second column of the first table in the document, starting from the second
row (assuming that there is a heading in the first row)

Dim A As Long, B As Long, C As Long, D As Long, i As Long
Dim arange As Range
A = 0
B = 0
C = 0
D = 0
With ActiveDocument.Tables(1).Columns(2)
For i = 2 To .Cells.Count
Set arange = .Cells(i).Range
arange.End = arange.End - 1
Select Case arange
Case "A"
A = A + 1
Case "B"
B = B + 1
Case "C"
C = C + 1
Case "D"
D = D + 1
End Select
Next i
End With
MsgBox "There are " & A & " A's; " & B & " B's; " & C & " C's and " & D & "
D's."


--
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
 
P

PaulM

Many Thanks. This does the job!

Doug Robbins - Word MVP said:
The following will sum the occurences of the A's, B's, C's and D's in the
second column of the first table in the document, starting from the second
row (assuming that there is a heading in the first row)

Dim A As Long, B As Long, C As Long, D As Long, i As Long
Dim arange As Range
A = 0
B = 0
C = 0
D = 0
With ActiveDocument.Tables(1).Columns(2)
For i = 2 To .Cells.Count
Set arange = .Cells(i).Range
arange.End = arange.End - 1
Select Case arange
Case "A"
A = A + 1
Case "B"
B = B + 1
Case "C"
C = C + 1
Case "D"
D = D + 1
End Select
Next i
End With
MsgBox "There are " & A & " A's; " & B & " B's; " & C & " C's and " & D & "
D's."


--
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