trying to dynamically sum a column

depcdivr

Active Member
Joined
Jan 21, 2008
Messages
349
Office Version
  1. 365
Platform
  1. Windows
HEllo. I am trying to use VBA to sum a column of numbers that I am populating into a spreadsheet.

I am compiling data into different spreadsheets. The length of the data will vary from spreadsheet but I am trying to use a single cold to populate the a Totals Row.

I use this code in order to sum across cells in a row and it works well but in that case it is always the 12 previous cells.

VBA Code:
wsps.Cells(Z, 16) = "=sum(RC[-12]:RC[-1])"

Here is what I am trying to use.

Code:
irow2 = wsm.Cells(Rows.Count, 1).End(xlUp).Row
        For Z = 4 To 55
            wsm.Cells(irow2 + 1, Z) = "=sum(R[-irow2]C:R[-1]C)"
        Next Z

Irow 2 will vary by spreadsheet so where I put the total needs to vary. I get it to print test code to the proper cells without an issue. There seems to be an issue with the Sum formula that I am using. Is it becasue I am trying to sum vertically and not horizontally?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Anything enclosed in double-quotes is literal text. So your variable has to be outside of the double-quotes.
So you need to sew all the pieces toegther, like this:
VBA Code:
"=sum(R[-" & irow2 & "]C:R[-1]C)"
 
Upvote 0
Solution

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top