Auto Sum using VBA

leviackerman13

New Member
Joined
Jan 2, 2024
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi. I would like to add the grades of every student and output it in the next row. What I want to to is in the red font. Please note that the record of student name varies.
1704178558284.png
 

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.
Hi,

This should do the job:
VBA Code:
Sub test()
  Dim i As Long
  Application.ScreenUpdating = False
  For i = 1 To Cells(Rows.Count, "B").End(xlUp).Row
    If Cells(i, "B").Value <> "" And Cells(i, "B").Value <> "Name" Then
      Cells(i, "B").End(xlDown).Offset(1, 1) = Application.Sum(Cells(i, "B").Offset(, 1).Resize(Cells(i, "B").End(xlDown).Row - i + 1))
      Cells(i, "B").End(xlDown).Offset(1, 2) = Application.Sum(Cells(i, "B").Offset(, 2).Resize(Cells(i, "B").End(xlDown).Row - i + 1))
      i = Cells(i, "B").End(xlDown).Row
    End If
  Next
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Hi,

This should do the job:
VBA Code:
Sub test()
  Dim i As Long
  Application.ScreenUpdating = False
  For i = 1 To Cells(Rows.Count, "B").End(xlUp).Row
    If Cells(i, "B").Value <> "" And Cells(i, "B").Value <> "Name" Then
      Cells(i, "B").End(xlDown).Offset(1, 1) = Application.Sum(Cells(i, "B").Offset(, 1).Resize(Cells(i, "B").End(xlDown).Row - i + 1))
      Cells(i, "B").End(xlDown).Offset(1, 2) = Application.Sum(Cells(i, "B").Offset(, 2).Resize(Cells(i, "B").End(xlDown).Row - i + 1))
      i = Cells(i, "B").End(xlDown).Row
    End If
  Next
  Application.ScreenUpdating = True
End Sub
Hi. Thank you very much. This works.
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,834
Members
449,471
Latest member
lachbee

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