VBA function to sum a full row - Loop for variable number of rows

eliudblabla

New Member
Joined
Sep 12, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

I´m faily new to VBA, and I´m having some issues trying to enter a function to sum the values of a row within a range of columns.

My document has a column for totals, and some other columns populated with data from another sheet. I want the totals column to sum the values in the remaining columns for that specific row.

Right now I´m stuck with the totals column showing the total sum for all values in all different rows, instead of only one row. Something similar to this:

TotalsBCDE
10001
51111
90121
120111

One thing to mention: the number of rows is variable, since they are populated based on certain criteria applied to data from another sheet, so I cannot reference specific cell values.

The code that I´ve used is this, where A is defined as the totals column in Sheet 1:

Worksheets("Sheet1").Activate
A = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet1").Cells(1 + 1, 1).Value = WorksheetFunction.Sum(Range("B:E"))

Can somebody please help with this?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try using
VBA Code:
 with Worksheets("Sheet1")
R = .Cells(Rows.Count, 2).End(xlUp).Row
.Range("A2:A" & R).formula = "=Sum("B2:E2")"
end with
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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