Saturday 9 January 2016

Macro to copy the sum of selected cells on selection


Object of the Macro : To get copied to the clipboard, the sum of the cells selected in a worksheet so that it can pasted directly without having to sum the numbers in the cell, copy the sum and then paste.

Macro:  

Sub CopySum()
Dim xOb As New DataObject
xOb.Clear
xOb.SetText Application.WorksheetFunction.Sum(Application.ActiveWindow.RangeSelection)
xOb.PutInClipboard
End Sub


If the macro throws a compile error that the "User-defined type not defined", here's the way-out


Open References in Word VBA

Click on Browse

Pick up this file and click Open

C:\WINDOWS\SYSTEM\FM20.DLL 


Courtesyhttps://answers.microsoft.com/en-us/msoffice/forum/all/mystery-compile-error-user-defined-type-not/b0c07a65-9f0c-43f1-a181-12c95db0ac8d

No comments:

Post a Comment