View Single Post
 
Old 07-10-2015, 11:49 AM
warbird warbird is offline Windows 7 64bit Office 2010 64bit
Novice
 
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