Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-12-2014, 08:06 AM
So New2 This So New2 This is offline Using data retreived from a loop in a calculation Windows XP Using data retreived from a loop in a calculation Office 2007
Novice
Using data retreived from a loop in a calculation
 
Join Date: May 2013
Location: Cleveland,OH
Posts: 3
So New2 This is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 10-12-2014, 10:55 AM
gmaxey gmaxey is offline Using data retreived from a loop in a calculation Windows 7 32bit Using data retreived from a loop in a calculation Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 10-12-2014, 03:53 PM
macropod's Avatar
macropod macropod is offline Using data retreived from a loop in a calculation Windows 7 64bit Using data retreived from a loop in a calculation Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Quote:
Originally Posted by So New2 This View Post
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.
You don't need VBA for this - it can all be done via field coding. To see how to do a wide range of calculations in Word, all using field codes, check out my Microsoft Word Field Maths Tutorial, at:
http://windowssecrets.com/forums/sho...Maths-Tutorial
or:
http://www.gmayor.com/downloads.htm#Third_party
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help with age calculation!!! Microsoft Idiot Word 4 10-29-2012 05:54 AM
Using data retreived from a loop in a calculation Formula calculation danbl Excel 8 02-23-2012 04:35 AM
Using data retreived from a loop in a calculation Calculation within Cells manich1 Excel 2 12-07-2011 02:59 PM
Using data retreived from a loop in a calculation Macro to loop in subfolders, change links, export xml data Catalin.B Excel Programming 2 09-08-2011 11:37 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:34 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