Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
formula in VB not working
I have several columns of figures with totals at the bottom. The leftmost
column is the grand total. I need to calculate what percentages the subtotals are of the grand total. This code sums the column, and works fine: Dim per1 As String per1 = "=sum(" & r3 & ":" & r4 & ")" ActiveCell.formula = per1 This code 'should' calculate the percentage, but the debugger sticks on the final line: Dim per2 As String per2 = "=sum(" & r3 & ":" & r4 & ")/(=sum(" & r1 & ":" & r2 & ")/100)" ActiveCell.formula = per2 What have I done? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
formula in VB not working
per2 = "=sum(" & r3 & ":" & r4 & ")/(sum(" & r1 & ":" & r2 & ")/100)"
That is, no "=" sign before the 2nd Sum. Of course I don't know if your r1 and r1 are right. You can always test the formula by entering it on the worksheet first and then read it in VBA with the .Formula property -- Kind regards, Niek Otten "Josie" <zeiderzeeAThotmailDOTcoDOTuk(DONOTSPAM) wrote in message ... I have several columns of figures with totals at the bottom. The leftmost column is the grand total. I need to calculate what percentages the subtotals are of the grand total. This code sums the column, and works fine: Dim per1 As String per1 = "=sum(" & r3 & ":" & r4 & ")" ActiveCell.formula = per1 This code 'should' calculate the percentage, but the debugger sticks on the final line: Dim per2 As String per2 = "=sum(" & r3 & ":" & r4 & ")/(=sum(" & r1 & ":" & r2 & ")/100)" ActiveCell.formula = per2 What have I done? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
formula in VB not working
Hi Niek. Thanks. That's fixed it!
"Niek Otten" wrote: per2 = "=sum(" & r3 & ":" & r4 & ")/(sum(" & r1 & ":" & r2 & ")/100)" That is, no "=" sign before the 2nd Sum. Of course I don't know if your r1 and r1 are right. You can always test the formula by entering it on the worksheet first and then read it in VBA with the .Formula property -- Kind regards, Niek Otten "Josie" <zeiderzeeAThotmailDOTcoDOTuk(DONOTSPAM) wrote in message ... I have several columns of figures with totals at the bottom. The leftmost column is the grand total. I need to calculate what percentages the subtotals are of the grand total. This code sums the column, and works fine: Dim per1 As String per1 = "=sum(" & r3 & ":" & r4 & ")" ActiveCell.formula = per1 This code 'should' calculate the percentage, but the debugger sticks on the final line: Dim per2 As String per2 = "=sum(" & r3 & ":" & r4 & ")/(=sum(" & r1 & ":" & r2 & ")/100)" ActiveCell.formula = per2 What have I done? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
A formula not working as the result of a previous formula? | Excel Discussion (Misc queries) | |||
Formula not working, help | Excel Worksheet Functions | |||
formula not working | New Users to Excel | |||
IF Formula Not Working | Excel Worksheet Functions | |||
Formula not working | Excel Worksheet Functions |