VBA Sum a Row of Data

Gian624

Board Regular
Joined
Jul 23, 2009
Messages
92
Hello,

I need to use VBA to sum a set of data on a row. The data is in cells B2 through M2. In the example, I have to use A1 as the range start point and use an offset to get me to cell B2. I then need to use the xlToRight function as the range to sum. I was thinking about using a with statement with the range as A1. I can't figure out how to sum the data from there.

Thanks for your help.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Your Object Browser can be a big help with syntax.
Offset is a member of the Range class.
xlToRight is a member of the Range.End class

Sum is not easy to do across a range in VBA - I'd probably establish names for the start and end of the range to be summed, then set cell (e.g.) A3="=sum(" & name1 & ":" & name2 & ")" . For clarity, I'd make the cell above this say something like "=total:". But unsure what your assignment allows/disallows.
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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