Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Peter Peter is offline
external usenet poster
 
Posts: 111
Default Counting rows based on a criteria

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
  #2   Report Post  
Posted to microsoft.public.word.tables
macropod macropod is offline
external usenet poster
 
Posts: 1,002
Default Counting rows based on a criteria

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



  #3   Report Post  
Posted to microsoft.public.word.tables
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 171
Default Counting rows based on a criteria

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


  #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



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying 200 default rows from excel print 74 only in word. Adjusting TOCto reflect page numbering Microsoft Word Help 3 September 20th 06 03:28 AM
counting for a sum w/ multiple criteria Michelle D via OfficeKB.com Mailmerge 2 December 14th 05 10:31 AM
Problem with Advanced selection Criteria JR Hester Mailmerge 2 November 3rd 05 07:24 PM
Use drop down lists to select specific criteria Diggles1972 Microsoft Word Help 1 July 16th 05 10:12 AM
counting rows of a given table OliverTwist Tables 2 April 27th 05 12:20 PM


All times are GMT +1. The time now is 12:07 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"