Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here is the data:
C F I J N O 1.17 4.45 2.79 7.24 8.47 8.47 1.23 2.12 2.12 2.61 2.61 7.81 7.81 is the sum of values in col F multiplied by their corresponding value in col C. So 7.81 should equal (1.17 * 4.45) + (1.23 * 2.12) ie 5.2065 + 2.6076 = 7.8141 round to 7.81 However, I need each multiplication to round. So 1.17 * 4.45 = 5.2065 = 5.21 and 1.23 * 2.12 = 2.6076 = 2.61 thus 5.21 + 2.61 = 7.82 Here's the code that currently sums the column: For ColNdx = 5 To 9 'cols E to I Cells(EndToCollectionRow - 1, ColNdx).FormulaArray = "=SUM((" & Range( _ Cells(StartToCollectionRow, "C"), Cells(EndToCollectionRow - 2, "C")) _ .Address & ")*(" & Range(Cells(StartToCollectionRow, ColNdx), _ Cells(EndToCollectionRow - 2, ColNdx)).Address & "))" Cells(EndToCollectionRow - 1, ColNdx).Value = _ Cells(EndToCollectionRow - 1, ColNdx).Text Next ColNdx Is there a way to modify the code, please? Regards. --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.655 / Virus Database: 420 - Release Date: 08/04/2004 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You could apply the ROUND statement for the sum.
round (sum();2) I didn't test it. Let us know. Ciao Alex. Stuart wrote: Here is the data: C F I J N O 1.17 4.45 2.79 7.24 8.47 8.47 1.23 2.12 2.12 2.61 2.61 7.81 7.81 is the sum of values in col F multiplied by their corresponding value in col C. So 7.81 should equal (1.17 * 4.45) + (1.23 * 2.12) ie 5.2065 + 2.6076 = 7.8141 round to 7.81 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks, but I think the chance to Round has passed by the time
the value hits the Sum cell. I guess I need to find a way to Round each calculation BEFORE its' result is added to the Sum....if you see what I mean. Regards "y" wrote in message ... You could apply the ROUND statement for the sum. round (sum();2) I didn't test it. Let us know. Ciao Alex. Stuart wrote: Here is the data: C F I J N O 1.17 4.45 2.79 7.24 8.47 8.47 1.23 2.12 2.12 2.61 2.61 7.81 7.81 is the sum of values in col F multiplied by their corresponding value in col C. So 7.81 should equal (1.17 * 4.45) + (1.23 * 2.12) ie 5.2065 + 2.6076 = 7.8141 round to 7.81 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.655 / Virus Database: 420 - Release Date: 08/04/2004 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Stuart wrote:
Thanks, but I think the chance to Round has passed by the time the value hits the Sum cell. I guess I need to find a way to Round each calculation BEFORE its' result is added to the Sum....if you see what I mean. Sorry Stuart, round globally the product this way .....formularray = SUM(ROUND(array1*array2;roundoff)) Choose the round off you desire. I tested this formula manually in a worksheeet and Excel allows it. Let us know. Alex. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Have amended to:
For ColNdx = 5 To 9 'cols E to I Cells(EndToCollectionRow - 1, ColNdx).FormulaArray = "=SUM(ROUND(" & Range( _ Cells(StartToCollectionRow, "C"), Cells(EndToCollectionRow - 2, "C")) _ .Address & ")*(" & Range(Cells(StartToCollectionRow, ColNdx), _ Cells(EndToCollectionRow - 2, ColNdx)).Address & "), 2)" Cells(EndToCollectionRow - 1, ColNdx).Value = _ Cells(EndToCollectionRow - 1, ColNdx).Text Next ColNdx and get "Unable to set the FormulaArray property of the Range class" error. Did I miscode your suggestion? Regards and thanks. "y" wrote in message ... Stuart wrote: Thanks, but I think the chance to Round has passed by the time the value hits the Sum cell. I guess I need to find a way to Round each calculation BEFORE its' result is added to the Sum....if you see what I mean. Sorry Stuart, round globally the product this way ....formularray = SUM(ROUND(array1*array2;roundoff)) Choose the round off you desire. I tested this formula manually in a worksheeet and Excel allows it. Let us know. Alex. --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.655 / Virus Database: 420 - Release Date: 08/04/2004 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What kind of testing have you done Stuart?
Sub Tester9() starttocollectionRow = 1 Endtocollectionrow = 8 colndx = 3 sStr = "=SUM(ROUND(" & Range( _ Cells(starttocollectionRow, "C"), Cells(Endtocollectionrow - 2, "C")) _ .Address & ")*(" & Range(Cells(starttocollectionRow, colndx), _ Cells(Endtocollectionrow - 2, colndx)).Address & "), 2)" Debug.Print sStr End Sub produces =SUM(ROUND($C$1:$C$6)*($C$1:$C$6), 2) so you have clearly miscoded it since this formula is in error. -- Regards, Tom Ogilvy "Stuart" wrote in message ... Have amended to: For ColNdx = 5 To 9 'cols E to I Cells(EndToCollectionRow - 1, ColNdx).FormulaArray = "=SUM(ROUND(" & Range( _ Cells(StartToCollectionRow, "C"), Cells(EndToCollectionRow - 2, "C")) _ .Address & ")*(" & Range(Cells(StartToCollectionRow, ColNdx), _ Cells(EndToCollectionRow - 2, ColNdx)).Address & "), 2)" Cells(EndToCollectionRow - 1, ColNdx).Value = _ Cells(EndToCollectionRow - 1, ColNdx).Text Next ColNdx and get "Unable to set the FormulaArray property of the Range class" error. Did I miscode your suggestion? Regards and thanks. "y" wrote in message ... Stuart wrote: Thanks, but I think the chance to Round has passed by the time the value hits the Sum cell. I guess I need to find a way to Round each calculation BEFORE its' result is added to the Sum....if you see what I mean. Sorry Stuart, round globally the product this way ....formularray = SUM(ROUND(array1*array2;roundoff)) Choose the round off you desire. I tested this formula manually in a worksheeet and Excel allows it. Let us know. Alex. --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.655 / Virus Database: 420 - Release Date: 08/04/2004 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
"num#" errors .. how to average a group with a "num#" error | Excel Discussion (Misc queries) | |||
"Document not saved" "error in loading DLL" | Excel Discussion (Misc queries) | |||
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell | Excel Discussion (Misc queries) | |||
change "true" and "false" to "availble" and "out of stock" | Excel Worksheet Functions | |||
Shortcut key for "Paste Options" and "Error Checking" buttons? | Excel Discussion (Misc queries) |