PDA

View Full Version : copy paste macro needs sum function



frank 7788
03-03-2016, 09:07 AM
Hello,
I'm new to VBA, and I can't get the code right for this macro. It would be great if it summed the cells selected
before paste. Any help would be appreciated.


Sub sample()
Dim rng as range, inp as range

If typename(selection) <> “Range” then
Msgbox “select a range first.”
Exit sub
Else
Set inp = selection
End if

Set rng = application.inputbox(“copy to”, type:=8)

If not rng is nothing then
Rng.parent.activate
Rng.select

Inp.copy
Activesheet.paste link:=true
End if
End sub

xld
03-03-2016, 04:20 PM
wouldn't you just add something like


MySum = Application.Sum(inp)