Hi and welcome to MrExcel!
Try this:
VBA Code:
Sub SumTotal()
Dim a As Variant
Dim i As Long, j As Long
Dim tot As Double
a = Range("C1", Cells(Range("A" & Rows.Count).End(3).Row, Cells(1, Columns.Count).End(1).Column)).Value
For i = 2 To UBound(a, 1)
For j = 1 To UBound(a, 2)
tot = tot + a(i, j)
If a(1, j) = "Total" Then
a(i, j) = tot
tot = 0
End If
Next
Next
Range("C1").Resize(UBound(a, 1), UBound(a, 2)).Value = a
End Sub
----------------
NOTE XL2BB:
For the future, it would help greatly if you could give us the sample data in a form that we can copy to test with, rather that a picture.
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here:
XL2BB Add-in
Note that there is also a "
Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
----------------
Example:
Dante Amor |
---|
|
---|
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
---|
1 | Name | Surname | Hour1 | Hour2 | Hour3 | Total | Hour1 | Hour2 | Hour3 | Hour4 | Hour5 | Total | Hour1 | Hour2 | Total |
---|
2 | nm1 | sn1 | 3 | 5 | 5 | | 4 | 1 | 3 | 5 | 3 | | 4 | 2 | |
---|
3 | nm2 | sn2 | 5 | 5 | 2 | | 4 | 1 | 3 | 1 | 2 | | 2 | 3 | |
---|
4 | nm3 | sn3 | 5 | 5 | 2 | | 3 | 2 | 5 | 2 | 5 | | 3 | 4 | |
---|
5 | nm4 | sn4 | 5 | 1 | 4 | | 5 | 5 | 4 | 2 | 2 | | 1 | 5 | |
---|
6 | nm5 | sn5 | 4 | 3 | 1 | | 2 | 5 | 1 | 2 | 1 | | 4 | 3 | |
---|
7 | nm6 | sn6 | 4 | 4 | 3 | | 1 | 3 | 4 | 1 | 1 | | 3 | 3 | |
---|
8 | nm7 | sn7 | 4 | 3 | 4 | | 5 | 4 | 4 | 1 | 4 | | 3 | 4 | |
---|
9 | nm8 | sn8 | 2 | 5 | 3 | | 4 | 4 | 2 | 4 | 3 | | 3 | 3 | |
---|
|
---|
Result:
Dante Amor |
---|
|
---|
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
---|
1 | Name | Surname | Hour1 | Hour2 | Hour3 | Total | Hour1 | Hour2 | Hour3 | Hour4 | Hour5 | Total | Hour1 | Hour2 | Total |
---|
2 | nm1 | sn1 | 3 | 5 | 5 | 13 | 4 | 1 | 3 | 5 | 3 | 16 | 4 | 2 | 6 |
---|
3 | nm2 | sn2 | 5 | 5 | 2 | 12 | 4 | 1 | 3 | 1 | 2 | 11 | 2 | 3 | 5 |
---|
4 | nm3 | sn3 | 5 | 5 | 2 | 12 | 3 | 2 | 5 | 2 | 5 | 17 | 3 | 4 | 7 |
---|
5 | nm4 | sn4 | 5 | 1 | 4 | 10 | 5 | 5 | 4 | 2 | 2 | 18 | 1 | 5 | 6 |
---|
6 | nm5 | sn5 | 4 | 3 | 1 | 8 | 2 | 5 | 1 | 2 | 1 | 11 | 4 | 3 | 7 |
---|
7 | nm6 | sn6 | 4 | 4 | 3 | 11 | 1 | 3 | 4 | 1 | 1 | 10 | 3 | 3 | 6 |
---|
8 | nm7 | sn7 | 4 | 3 | 4 | 11 | 5 | 4 | 4 | 1 | 4 | 18 | 3 | 4 | 7 |
---|
9 | nm8 | sn8 | 2 | 5 | 3 | 10 | 4 | 4 | 2 | 4 | 3 | 17 | 3 | 3 | 6 |
---|
|
---|