Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
Cool! Perfect!
Thanks very much for your help. Carolyn |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Inserting a Full Width Table in a 2 Column Document | Page Layout | |||
Document Styles should be assignable to fonts in Table AutoFormat | Tables | |||
insert table command inserts only a single column and row table | Tables | |||
How to paste a column of text into a column in a Word Table | Page Layout | |||
Remove Rows from a Table after merging | Mailmerge |