#1
|
|||
|
|||
Using data retreived from a loop in a calculation
I have a Word table that has 9 cells. I need help with looping through the different cells to get the data so I can use these values in different calculations. For instance the data in cell 2 and 3 needs to be calculated, then the the data in cell 4 and 5 needs to be calculated. The results of these two calculations then needs to be calculated and copied to a different table on the report. I have the loop so it returns the different values, I'm just unclear how to store these values so they can be used. |
#2
|
|||
|
|||
I don't understand your question. The values are already contained in cells 2, 3, 4 and 5:
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oTbl As Word.Table Dim dblOne As Double, dblTwo As Double Set oTbl = ActiveDocument.Tables(1) dblOne = CDbl(fcnGetCellText(oTbl.Cell(2, 1))) + CDbl(fcnGetCellText(oTbl.Cell(3, 1))) dblTwo = CDbl(fcnGetCellText(oTbl.Cell(4, 1))) + CDbl(fcnGetCellText(oTbl.Cell(5, 1))) ActiveDocument.Tables(2).Cell(1, 1).Range.Text = dblOne + dblTwo 'or ActiveDocument.Tables(2).Cell(2, 1).Range.Text = (CDbl(fcnGetCellText(oTbl.Cell(2, 1))) _ + CDbl(fcnGetCellText(oTbl.Cell(3, 1))) _ + (CDbl(fcnGetCellText(oTbl.Cell(4, 1))) _ + CDbl(fcnGetCellText(oTbl.Cell(5, 1))))) End Sub Function fcnGetCellText(oCell) As String fcnGetCellText = Left(oCell.Range.Text, Len(oCell.Range.Text) - 2) End Function |
#3
|
||||
|
||||
Quote:
http://windowssecrets.com/forums/sho...Maths-Tutorial or: http://www.gmayor.com/downloads.htm#Third_party
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Please help with age calculation!!! | Microsoft Idiot | Word | 4 | 10-29-2012 05:54 AM |
Formula calculation | danbl | Excel | 8 | 02-23-2012 04:35 AM |
Calculation within Cells | manich1 | Excel | 2 | 12-07-2011 02:59 PM |
Macro to loop in subfolders, change links, export xml data | Catalin.B | Excel Programming | 2 | 09-08-2011 11:37 PM |