How to Copy/Paste the Sum of Selected Cells in Excel
I've booked about three hundred hours plus of work in March. This is not by choice, it's just the nature of the business, but I am always looking for ways to be more efficient. As an auditor, there are a lot of menial tasks that can be eliminated with macros in excel files. We are interested in totals and it's a pain to have to copy a set of numbers into another worksheet and sum them up to get the number you need. Typically when you highlight a set of numbers the total will appear on the bottom left hand corner. I wanted to be able to copy that total directly and paste it in a separate spreadsheet.
Here is a macro that will help you do that.
Refer to the below five step process:
1) Hit Alt + F11 (this will open the VBE Window)
2) Select 'Module' from the 'Insert Menu' and paste the code below.
Sub mySum()
Dim MyDataObj As New DataObject
MyDataObj.SetText Application.Sum(Selection)
MyDataObj.PutInClipboard
End Sub
3) Select 'References' from the 'Tool Menu' and make sure 'Microsoft Forms 2.0 Object Library' is selected. If it's not listed then click 'browse' and select 'Fm20.dll'
4) Close the VBE window
5) Hit Alt + F8, select 'mySum', click 'Options' and set your shortcut key.
22 comments :
This solution was exactly what I was looking for! It was clearly written, easy to implement, and required no guess work on my part. Thanks for sharing your knowledge Kevin!
-Justin G, Minneapolis
Thanks kevin. From fellow auditor
Hey thanks for the post - has saved me tons of time.
BUT if you have a filter on your data that you want to sum, you need to change
"MyDataObj.SetText Application.Sum(Selection)"
to
"MyDataObj.SetText Application.Subtotal(9, Selection)"
Thanks for sharing the tip and explaining it so well as well ;)
Very helpful!
I also went searching for a way to copy the sum only of selected cells and found I put the following in, and it worked.
MyDataObj.SetText Application.Sum(Selection.SpecialCells(xlCellTypeVisible))
Hi,
Best instruction ever, worked perfectly.
Thanks!
Ari,
Thanks, Worked perfectly. Saved me hours!
Incredibly helpful. Thanks for the very clear instructions!
Thanks for sharing your very helpful knowledge. Zeljko
Thank you so much!!
Thank you so much!! Just what i was looking for.
Very cool. Just what I need. Thank you!
Thanks this is great!
Wonderful!!! But can you give us a way to copy and paste the AVERAGE of selected cells?
Ok I simply put average wherever you had put sum and it worked!!!!!!!!!!!!!!!
Thank you so much
Very nice!
Oh my, this is brilliant!! Thank you so much for sharing!
That is a very useful post - thank you!
I usually don't leave a comment on blog posts that have proved useful, but I must say that you are a productivity genius!
Thanks Superb !
Great, thank you!
I've been looking for this for years -- thanks -- works just as advertised!
Post a Comment