adding vba macro

delta59

New Member
Joined
Jun 18, 2011
Messages
11
hey I need help writing a macro that adds 2 values in a col. and then carries the total and keeps going to row 5000. The problem is the number of rows inbetween each number is always variable and the sum needs to return to the same position(if that cant be done results can be move to col B). For example I have a set of data that looks like this, and what needs to happen. Thanks in advance

col A | col A(after macro)

21 | 21

blank | blank

blank | blank

blank | blank

35 | 56

blank | blank

-22 | 34

blank | blank

blank | blank

5 | 39
 
Last edited:

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
Code:
Sub Running_Total_A()

    Dim rngA As Range, a As Variant, i As Long, tot As Double
    
    Set rngA = Range("A2", Range("A" & Rows.Count).End(xlUp))
    a = rngA.Value
    
    For i = 1 To UBound(a)
        If IsNumeric(a(i, 1)) And a(i, 1) <> "" Then
            tot = tot + a(i, 1)
            a(i, 1) = tot
        End If
    Next i
    rngA.Value = a
    
End Sub
 
Upvote 0
Give this macro a try (it should execute pretty quickly)....
Code:
Sub EnterSums()
  Application.ScreenUpdating = False
  Range("B1:B" & Cells(Rows.Count, "A").End(xlUp).Row).Formula = "=SUM(A$1:A1)"
  With Columns("A").SpecialCells(xlCellTypeBlanks)
    .Offset(, 1).Value = .Value
  End With
  Columns("B").Value = Columns("B").Value
  With Columns("A").SpecialCells(xlCellTypeConstants)
    .Value = .Offset(, 1).Value
  End With
  Columns("A").Delete
  Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,909
Members
452,949
Latest member
beartooth91

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