![]() |
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? |
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? |
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? |
All times are GMT +1. The time now is 12:31 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com