MPW
Well-known Member
- Joined
- Oct 7, 2009
- Messages
- 571
- Office Version
- 365
- Platform
- Windows
I am dynamically populating a blank sheet with contents from another sheet. I want to sum certain columns. Here is what I am using.
When run it apparently creates the formulas correctly, however they are summing the wrong columns. For example:
creates
If I am reading the r1c1 ref correctly this should sum ("D2:D40"). Instead it sums ("H2:H40").
If I convert to traditional formulas it looks like ("H2:H40"). This is the 1st time I tried to construct r1c1 formulas like this. So what am I missing?
Please show me a better way.
Code:
cr = Sheets("X").Cells(1, Columns.Count).End(xlToLeft).Column
For c3 = 1 To cr
If Left(Sheets("X").Cells(1, c3), 1) = "#" Then
rall = Sheets("X").Cells(Rows.Count, c3).End(xlUp).Row
Sheets("X").Cells(1, c3 + 1).Formula = & _
"=Sum(R[" & 2 & "]C[" & c3 + 1 & "]:R[" & rall & "]C[" & c3 + 1 & "])"
Sheets("X").Cells(1, c3 + 2).Formula = & _
"=Sum(R[" & 2 & "]C[" & c3 + 2 & "]:R[" & rall & "]C[" & c3 + 2 & "])"
End If
Next c3
When run it apparently creates the formulas correctly, however they are summing the wrong columns. For example:
Code:
"=Sum(R[" & 2 & "]C[" & c3 + 1 & "]:R[" & rall & "]C[" & c3 + 1 & "])"
Code:
=SUM(R[2]C[4]:R[40]C[4])
If I convert to traditional formulas it looks like ("H2:H40"). This is the 1st time I tried to construct r1c1 formulas like this. So what am I missing?
Please show me a better way.