View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Invoke AutoSum From VBA?

With the cells with the values to sum selected:
CommandBars.FindControl(Id:=226).Execute



To create the formula:

Sub SumAtBottomOfCurrentColumn()
Dim myCell As Range
Set myCell = Cells(65536, ActiveCell.Column).End(xlUp)(2)
With myCell
.Formula = "=SUM(" & _
Range(.Offset(-1, 0), _
Cells(2, .Column)).Address(False, False) & ")"
End With
End Sub


HTH,
Bernie
MS Excel MVP


"PeteCresswell" wrote in message
...
I've got a cell selected.

Now I'd like the macro to invoke the AutoSum icon (the little sigma..)
that sums the columns above the selected column.

But when I try to record a macro, it comes up with the result of the
AutoSum (e.g. "=SUM(D3:D8)") instead of a call to AutoSum.

Is there a way?

The agenda is tb able to create a sum per the rules built into the
AutoSum icon and make it bold with a single Ctl+(letter) stroke.

I guess the obvious is to start at the selected cell, iterate upwards
until a blank cell is found, and then do an =Sum() of what's between.

But before I did that, I wanted to see if I was missing something with
AutoSum.