vba command to autosum range with multiple columns

B

BRC

Can anyone tell me if there is vba command to auto sum a range
similar
to pushing the autosum button ∑ in excel 2007? In this situation the
cells may not always be in the same location so hard coding not
practical. I can select the range, but can't find command to autosum.
I found the the snippet below but it generates error in excel 2007.
Thanks for any advice. BRC
CommandBars.FindControl(ID:=3D226).Execute 'AutoSum
 
D

Dave Peterson

I'm not sure what you're doing, but maybe you could use something like:

dim myTotal as double

mytotal = application.sum(selection)
or
mytotal = application.sum(activesheet.range("A1:b9,d3:x99"))
 
V

Varne

Hi!

Sub SummingUpSelections()

Dim MySelections As String
Dim MyFormula As String
Dim MySpace As Range

Set MySpace = Worksheets(2).Cells(1, 1) ' Use any different sheet

MySelections = Selection.Address

MyFormula = "" & "=" & "Sum(" & MySelections & ")"

MsgBox MySpace

End Sub

M Varnendra
 
B

BRC

Hi!

Sub SummingUpSelections()

Dim MySelections As String
Dim MyFormula As String
Dim MySpace As Range

Set MySpace = Worksheets(2).Cells(1, 1) ' Use any different sheet

MySelections = Selection.Address

MyFormula = "" & "=" & "Sum(" & MySelections & ")"

MsgBox MySpace

End Sub

M Varnendra





- Show quoted text -

Thank you all for the responses. I actually found the solution in
this forum in a post titled "Invoke AutoSum From VBA?" and it works
perfectly. I am not sure why I didn't see this when i searched
before my post. If I would have serached on "autosum" only I
prrobably would have found it thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top