Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
kaz
 
Posts: n/a
Default Count table rows with specific value in a column

Hi there

I have a table where I am counting the number of rows, excluding the
header row, with the result of the count being displayed in another
part of the Word document. That works very well using a macro (after I
sought advice here a while back).

Now I am told I need to have two counts displaying information from
this table. The first is the one I have already got. The second is a
count of rows in the table, excluding the header row, where one of the
columns has a value of A or M. Any clues on how I can achieve that?

Carolyn

  #2   Report Post  
Posted to microsoft.public.word.tables
Greg Maxey
 
Posts: n/a
Default Count table rows with specific value in a column

I am assuming that you mean a single "A" or a single "M" in the cell.

Try:
Sub RowCnt()
Dim oTbl As Word.Table
Dim oRows As Rows
Dim pColCnt As Long
Dim i As Long
Dim j As Long
Dim oCell As Word.Range
Dim oCnt As Long
Set oTbl = Selection.Tables(1)
Set oRows = oTbl.Rows
For i = 2 To oRows.Count
pColCnt = oTbl.Rows(i).Cells.Count
For j = 1 To pColCnt
Set oCell = oTbl.Cell(i, j).Range
oCell.MoveEnd wdCharacter, -1
Select Case oCell.Text
Case "M"
oCnt = oCnt + 1
Exit For
Case "A"
oCnt = oCnt + 1
Exit For
Case Else
'Do Nothing
End Select
Next j
Next i
MsgBox oCnt
End Sub


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


kaz wrote:
Hi there

I have a table where I am counting the number of rows, excluding the
header row, with the result of the count being displayed in another
part of the Word document. That works very well using a macro (after I
sought advice here a while back).

Now I am told I need to have two counts displaying information from
this table. The first is the one I have already got. The second is a
count of rows in the table, excluding the header row, where one of the
columns has a value of A or M. Any clues on how I can achieve that?

Carolyn



  #3   Report Post  
Posted to microsoft.public.word.tables
kaz
 
Posts: n/a
Default Count table rows with specific value in a column

Hi Greg
Yes it is for a single M or A. That macro is great! Of course I always
forget to mention at least one thing......

There are two potential columns which can contain these values but I
only want to include the rows where the value is in a specific column -
the 6th column.

Carolyn

  #4   Report Post  
Posted to microsoft.public.word.tables
Greg Maxey
 
Posts: n/a
Default Count table rows with specific value in a column

OK, try:
Sub RowCnt()
Dim oTbl As Word.Table
Dim oRows As Rows
Dim pColCnt As Long
Dim i As Long
Dim oCell As Word.Range
Dim oCnt As Long
Set oTbl = Selection.Tables(1)
Set oRows = oTbl.Rows
For i = 2 To oRows.Count
If oTbl.Rows(i).Cells.Count = 6 Then
Set oCell = oTbl.Cell(i, 6).Range
oCell.MoveEnd wdCharacter, -1
Select Case oCell.Text
Case "M"
oCnt = oCnt + 1
Case "A"
oCnt = oCnt + 1
Case Else
'Do Nothing
End Select
End If
Next i
MsgBox oCnt
End Sub

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


kaz wrote:
Hi Greg
Yes it is for a single M or A. That macro is great! Of course I always
forget to mention at least one thing......

There are two potential columns which can contain these values but I
only want to include the rows where the value is in a specific column
- the 6th column.

Carolyn



  #5   Report Post  
Posted to microsoft.public.word.tables
kaz
 
Posts: n/a
Default Count table rows with specific value in a column

Cool! Perfect!

Thanks very much for your help.

Carolyn

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
Inserting a Full Width Table in a 2 Column Document BJC Page Layout 3 May 17th 23 08:48 AM
Document Styles should be assignable to fonts in Table AutoFormat Natasha A. Tables 5 November 11th 05 05:49 PM
insert table command inserts only a single column and row table nova63 Tables 2 September 29th 05 02:34 AM
How to paste a column of text into a column in a Word Table Sam Page Layout 2 July 31st 05 08:03 PM
Remove Rows from a Table after merging Kevin L Mailmerge 1 December 9th 04 11:13 AM


All times are GMT +1. The time now is 11:46 AM.

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

About Us

"It's about Microsoft Word"