Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Recording a Macro in a table to count the sum
Hi,
I am trying to record a macro in a table to count the sum of requirements 1. The table has 3 columns which contain the requirements 2. The macro has to add all the columns and display the total in the last row 3. The macro has to take care of creation of new row of requirements for the total If anybody has done this earlier, if you can share the idea, it would be great -- Thanks Srinivas |
#2
|
|||
|
|||
If you run the following macro when the selection is in the result cell of
the first column (it need not be the first column in the table), it will do what you want. It assumes that the first row in the table contains headings Dim i As Long, j As Long, numrange As Range, numtab As Table Dim numcol As Long, numrow As Long Dim result As Double Set numtab = Selection.Tables(1) numcol = Selection.Information(wdEndOfRangeColumnNumber) numrow = Selection.Information(wdEndOfRangeRowNumber) For i = numcol To numcol + 2 result = 0 For j = 2 To numrow - 1 Set numrange = numtab.Cell(j, i).Range numrange.End = numrange.End - 1 result = result + numrange Next j numtab.Cell(numrow, i).Range.InsertBefore result Next i -- 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 "Srinivas MV" wrote in message news Hi, I am trying to record a macro in a table to count the sum of requirements 1. The table has 3 columns which contain the requirements 2. The macro has to add all the columns and display the total in the last row 3. The macro has to take care of creation of new row of requirements for the total If anybody has done this earlier, if you can share the idea, it would be great -- Thanks Srinivas |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Table in a Form | Tables | |||
Possible bug when recording a Word Macro | Microsoft Word Help | |||
Table AutoFormats vs. Table Styles confusion | Tables | |||
Ideas for macro to add row for count and percentage | Tables | |||
Word 2003 Table AutoFormat vs Macro vs VBA | Tables |