View Single Post
  #4   Report Post  
Posted to microsoft.public.word.tables
Peter Peter is offline
external usenet poster
 
Posts: 111
Default Counting rows based on a criteria

That worked nicely, thanks!!

"Greg Maxey" wrote:

Peter,

If you want a macro solution you might try the macro below. It assumes
that you have two (2 column) tables in the document. Table 1 list the
problem in column 1 and the priority in column 2. Table 2 has a
heading row and names the priority in column 1 and the count in column
2.

Sub ScratchMacro()
Dim oTbl As Word.Tables
Dim pPri1 As Long
Dim pPri2 As Long
Dim pPri3 As Long
Dim oCell As Cell
Set oTbl = ActiveDocument.Tables
For Each oCell In oTbl(1).Columns(2).Cells
Select Case Val(oCell.Range.Text)
Case 1
pPri1 = pPri1 + 1
Case 2
pPri2 = pPri2 + 1
Case 3
pPri3 = pPri3 + 1
End Select
Next
With oTbl(2)
.Cell(2, 2).Range.Text = pPri1
.Cell(3, 2).Range.Text = pPri2
.Cell(4, 2).Range.Text = pPri3
End With
End Sub

macropod wrote:
Hi Peter,

You'd be better off doing this on Excel - or at least an Excel worksheet
embedded in your Word document. That way, you'd have access to Excel's
COUNTIF function, which is designed to do this sort of thing. Word's field
functions don't include anything like COUNTIF. Alternatively, you could use
a macro.

Cheers

--
macropod
[MVP - Microsoft Word]


"Peter" wrote in message
...
Hi,

I have a table where I record faults and errors related to the

construction
of a house. Each record is given a priority from 1 to 3. Now, is it

possible
to construct another table, and then count the number of priority 1's, 2's
and 3's in the other table (I know about Count() and how to reference a
column in another table, but I can't get it to count records based on a
criteria).

Hopefully someone knows the answer to this one