ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy (https://www.excelbanter.com/excel-programming/413401-copy.html)

pwz[_2_]

Copy
 
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



Dave Peterson

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

copyfrom.copy
activecell.pastespecial ....



pwz wrote:

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


--

Dave Peterson

Dave Peterson

Copy
 
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

pwz wrote:

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


--

Dave Peterson

pwz[_2_]

Copy
 
Dear Dave,

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

"Dave Peterson" wrote in message
...
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

pwz wrote:

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


--

Dave Peterson





All times are GMT +1. The time now is 11:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com