Auto Sum in a Macro

cpezzer

New Member
Joined
Dec 21, 2005
Messages
2
Hi I have created the following code to autosum a large number of rows of data, around 80000 in total, which is far too slow to do manaually.

The code works fine in terms of a loop and perfectly if you run the insert autosum as a single function outside of the loop. However the two together clash and im not sure how to resolve this. i can leave this running overnight so if it takes a tad longer to do it a different way thats fine.

Can anyone please help me resolve why it jams?

Thanks

Chris


Sub autosumloop()

Do Until ActiveCell = Empty And ActiveCell.Offset(1) = Empty

If ActiveCell = Empty Then
CommandBars.FindControl(ID:=226).Execute
Application.SendKeys ("~")
Application.SendKeys ("~")
Else
ActiveCell.Offset(1).Select
End If


Loop
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi cpezzer, the following code works with data in Column A stsrting from A1. Post for feedback

Ciao

Andrea


Code:
Sub AutoSum()
'
' AutoSum Macro
'
Dim SumCell As Range, FirstCell As Range, LastCell As Range
If Range("A1") <> "" Then
    Set FirstCell = Range("A65536").End(xlUp).Offset(2, 0)
    While FirstCell.Row > 1
        Set SumCell = FirstCell.Offset(-1, 0)
        Set LastCell = SumCell.Offset(-1, 0)
        If LastCell.Offset(-1, 0) = "" Then
            Set FirstCell = LastCell
        Else
            Set FirstCell = LastCell.End(xlUp)
        End If
        With SumCell
            .Formula = "=SUM(" & Range(FirstCell, LastCell).Address(False, False, xlA1) & ")"
            .Font.Bold = True
            .Font.ColorIndex = 3
        End With
    Wend
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,194
Members
449,072
Latest member
DW Draft

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