Copy

  • Thread starter Thread starter pwz
  • Start date Start date
P

pwz

Hi All,

Any error with the codes below? The input box is correctly popped up but
nothing or some other text is pasted.

Sub NewCopy()

Set CopyFrom = Application.InputBox(prompt:="Copy FROM?", Type:=8)
Range(CopyFrom).Copy
ActiveCell.PasteSpecial Paste:=xlPasteAll, operation:=xlNone

End Sub


Thanks in advance!

pwz
 
CopyFrom is already a range. So you don't surround it with range().

copyfrom.copy
activecell.pastespecial ....
 
In fact, you may want to allow the user to cancel the selection:

Sub NewCopy()
dim CopyFrom as range

set copyfrom = nothing
on error resume next
Set CopyFrom = Application.InputBox(prompt:="Copy FROM?", Type:=8)
on error goto 0

if copyfrom is nothing then
exit sub 'or something else??
end if

CopyFrom.Copy
ActiveCell.PasteSpecial Paste:=xlPasteAll, operation:=xlNone

End Sub
 
Dear Dave,

Great thanks to your additional suggestion! The codes work excellently.
 

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

Back
Top