#1
|
|||
|
|||
Code to Sum Column of Content Control Values In Specific Tables?
The Code below sums (content control) values in a table; column/cell 2 rows 3 through 11 and places the result in column/cell 2 of row 12. This works but surely there's a cleaner way to write it. I have 10 more tables with varying numbers of rows to apply it to.
Private Sub SumPoints() Dim Pts1 As Integer, Pts2 As Integer, Pts3 As Integer, Pts4 As Integer, Pts5 As Integer, Pts6 As Integer, Pts7 As Integer, Pts8 As Integer, PtsX As Integer With ActiveDocument With .Tables(2).Range Pts1 = Val(.Rows(3).Cells(2).Range.Text) Pts2 = Val(.Rows(4).Cells(2).Range.Text) Pts3 = Val(.Rows(5).Cells(2).Range.Text) Pts4 = Val(.Rows(6).Cells(2).Range.Text) Pts5 = Val(.Rows(7).Cells(2).Range.Text) Pts6 = Val(.Rows(8).Cells(2).Range.Text) Pts7 = Val(.Rows(9).Cells(2).Range.Text) Pts8 = Val(.Rows(10).Cells(2).Range.Text) PtsX = Val(.Rows(11).Cells(2).Range.Text) .Rows(12).Cells(2).Range.ContentControls(1).Range. Text = Pts1 + Pts2 + Pts3 + Pts4 + Pts5 + Pts6 + Pts7 + Pts8 + PtsX End With End Sub The cells share a column but I can't figure out the code syntax to create a column range (or quite what to do with it if I do). I'm struggling with the transition from ActiveX to Content Controls. Any help will be appreciated. Thx Joel |
#2
|
||||
|
||||
Is there a reason you can't use a formula field for the summation?
PS: When posting code, please use the code tags, indicated by the # button on the posting menu.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
I was trying not to use any fields, just content controls. A formula field does make it simpler overall.
(I see the hash-tag button now) |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Clicking the selected Content Control checkbox returns wrong control in vba event | DougsGraphics | Word VBA | 2 | 06-24-2015 07:31 AM |
Mouseover cell to indicate mouse pointer location based on Specific Row/Column values | bolandk | Excel | 1 | 05-15-2014 08:22 AM |
Deleting a table from a content control -- preserving the content control | BrainSlugs83 | Word Tables | 8 | 11-14-2013 03:06 AM |
Content control merge values? | skrallemand | Word VBA | 8 | 10-02-2013 06:54 AM |
Assigning Values to content control checkboxes and calculating results | creative cathy | Word Tables | 13 | 10-07-2012 08:52 PM |