Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-10-2015, 11:49 AM
warbird warbird is offline Code to Sum Column of Content Control Values In Specific Tables? Windows 7 64bit Code to Sum Column of Content Control Values In Specific Tables? Office 2010 64bit
Novice
Code to Sum Column of Content Control Values In Specific Tables?
 
Join Date: Jun 2015
Posts: 13
warbird is on a distinguished road
Question 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
Reply With Quote
  #2  
Old 07-10-2015, 07:53 PM
macropod's Avatar
macropod macropod is offline Code to Sum Column of Content Control Values In Specific Tables? Windows 7 64bit Code to Sum Column of Content Control Values In Specific Tables? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 07-13-2015, 05:44 AM
warbird warbird is offline Code to Sum Column of Content Control Values In Specific Tables? Windows 7 64bit Code to Sum Column of Content Control Values In Specific Tables? Office 2010 64bit
Novice
Code to Sum Column of Content Control Values In Specific Tables?
 
Join Date: Jun 2015
Posts: 13
warbird is on a distinguished road
Default

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)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to Sum Column of Content Control Values In Specific Tables? 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
Code to Sum Column of Content Control Values In Specific Tables? Deleting a table from a content control -- preserving the content control BrainSlugs83 Word Tables 8 11-14-2013 03:06 AM
Code to Sum Column of Content Control Values In Specific Tables? Content control merge values? skrallemand Word VBA 8 10-02-2013 06:54 AM
Code to Sum Column of Content Control Values In Specific Tables? Assigning Values to content control checkboxes and calculating results creative cathy Word Tables 13 10-07-2012 08:52 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:30 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft