Reply
 
Thread Tools Display Modes
  #1   Report Post  
Srinivas MV
 
Posts: n/a
Default 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   Report Post  
Doug Robbins
 
Posts: n/a
Default

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

Posting Rules

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Table in a Form HiDbLevel Tables 12 February 27th 06 12:59 PM
Possible bug when recording a Word Macro Raven95 Microsoft Word Help 4 April 30th 05 09:49 PM
Table AutoFormats vs. Table Styles confusion Tony Jollans Tables 5 March 6th 05 07:18 PM
Ideas for macro to add row for count and percentage Bradley C. Hammerstrom Tables 8 January 6th 05 10:38 AM
Word 2003 Table AutoFormat vs Macro vs VBA Kind writer/user/programmer Tables 1 October 28th 04 03:14 PM


All times are GMT +1. The time now is 07:25 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"