ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   "=sum(variable:variable2)" (https://www.excelbanter.com/excel-programming/327945-%3Dsum-variable-variable2.html)

KyWilde

"=sum(variable:variable2)"
 
I would like to put this formula into a specific cell. Here is my code:
for Counter 1 to 20
Cells((OneWkRow + 8), Counter).Value = "=Sum(c1_right_1 : c_right_1)"
Next Counter

Why is this not working? Can I not use variables in this instance? How can
I make this work? Thanks!!!

Rowan[_2_]

"=sum(variable:variable2)"
 
Everything between " and " is treated as a string. Try something like

Cells((OneWkRow + 8), Counter).Value = _
"=Sum(" & c1_right_1 &":" & c_right_1 & ")"

HTH
Rowan

"KyWilde" wrote:

I would like to put this formula into a specific cell. Here is my code:
for Counter 1 to 20
Cells((OneWkRow + 8), Counter).Value = "=Sum(c1_right_1 : c_right_1)"
Next Counter

Why is this not working? Can I not use variables in this instance? How can
I make this work? Thanks!!!


Patrick Molloy[_2_]

"=sum(variable:variable2)"
 
You have 20 columns starting at A.
You have 7 days data - in my example these are rows 5 to 11 , so OneWkStart
is set to row 5
In the next row, row 12, you want to add the values in the columns for the
week?

Try this as an alternative

Sub Demo()
Dim OneWkRow As Long
OneWkRow = 5

With Range(Cells(OneWkRow + 7, 1), Cells(OneWkRow + 7, 20))
.FormulaR1C1 = "=Sum(R[-8]C:R[-1]C)"
End With

End Sub



"KyWilde" wrote:

I would like to put this formula into a specific cell. Here is my code:
for Counter 1 to 20
Cells((OneWkRow + 8), Counter).Value = "=Sum(c1_right_1 : c_right_1)"
Next Counter

Why is this not working? Can I not use variables in this instance? How can
I make this work? Thanks!!!



All times are GMT +1. The time now is 12:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com