I am trying to set up a macro that will scroll through a row of data on my worksheet until it hits an empty cell, and then it will add up the cell values before that cell and enter that value into the empty cell. Then it will continue going until the end of the row. I was able to find a sample of code that does this exact function but with the data in a single column, and not a single row. And I have tried to just change the values around a little bit, but am not having any luck. For example, my data looks similar to this...
1, empty, 1, 1, empty, 1, 1, 1, empty
Here is the code that I got working for the values if they are in a single column..
![]()
Sub InsertTotals() Dim StartRow As Integer Dim EndRow As Integer StartRow = 1 EndRow = Range("A20").End(xlUp).Offset(1, 0).Row For i = StartRow To EndRow If Cells(i, "A") = "" And i > StartRow Then Cells(i, "A").Formula = "=SUM(A" & StartRow & ":A" & i - 1 & ")" StartRow = i + 1 End If Next End Sub
Bookmarks