About the sum function

Hernan_g_f

New Member
Joined
Jul 26, 2022
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have a matrix in Excel in a worksheet "1" in a workbook "Workboo1.xlsm"

Column 1 Column 2 Column 3 Column 7

Row 1 1 4 4 sum (A1: C1)
Row 2 0 4 5 sum (A2: C2)
Row 3 8 10 11 sum (A3:C3)

Row 5 sum sum sum
(A1:A3) (B1:B3) (C1:C3)

How can I wrote in VBA language the sum function for the rows and colunms?
And if I want to copy the column 7 in column 10 as value?

Many thanks for your help!
Hernán
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You can use the SUM function in VBA by prefacing it with "Application.WorksheetFunction.Sum", i.e.
VBA Code:
Sub MyTest()
    Dim rng As Range
    Set rng = Range("A1:C1")
    MsgBox Application.WorksheetFunction.Sum(rng)
End Sub
 
Upvote 1
Row 5 sum sum sum
(A1:A3) (B1:B3) (C1:C3)
So, if you want to populate row 5 with the sums of each of those, you could also use this (to input the SUM formulas in row 5):
VBA Code:
    Range("A5:C5").FormulaR1C1 = "=SUM(R[-4]C:R[-2]C)"
(you can get this code by simply turning on your Macro Recorder and entering the sum formulas in row 5).

If you wanted to change those to hard-coded values, you can then follow the line above with:
VBA Code:
    Range("A5:C5").Value = Range("A5:C5").Value
 
Upvote 1
Solution

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

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