What code are you using to copy and paste?
This is a discussion on Copying range from a single cell reference within the Excel Questions forums, part of the Question Forums category; I have the following code: Sub GetUserRange() Dim UserRangeOutput As Range Dim UserRangeInput As Range Dim Output As Range Prompt ...
I have the following code:
Sub GetUserRange()
Dim UserRangeOutput As Range
Dim UserRangeInput As Range
Dim Output As Range
Prompt = "Select the cells for the input."
Title = "Select a cell"
' Display the Input Box
On Error Resume Next
Set UserRangeInput = Application.InputBox( _
Prompt:=Prompt, _
Title:=Title, _
Default:=ActiveCell.Address, _
Type:=8) 'Range selection
On Error GoTo 0
' Was the Input Box cancelled?
If UserRangeInput Is Nothing Then
MsgBox "Cancelled"
End If
Prompt = "Select a cell for the output."
Title = "Select a cell"
' Display the Input Box
On Error Resume Next
Set UserRangeOutput = Application.InputBox( _
Prompt:=Prompt, _
Title:=Title, _
Default:=ActiveCell.Address, _
Type:=8) 'Range selection
On Error GoTo 0
' Was the Input Box cancelled?
If UserRangeOutput Is Nothing Then
MsgBox "Cancelled"
Else
UserRangeOutput.Range("A1") = UserRangeInput
End If
End Sub
The code works fine if only one cell is selected to copy from, and either a single or multiple cell is selected as the destination.
However, the code does not work at all if multiple cells are selected as the source - ie nothing is copied into the destination cells.
How can I change it so that a range (ie multiple cells) is copied, and then pasted into the destination cells?
Any help greatly appreciated.
Cheers
pvr928
What code are you using to copy and paste?
Jacob
I have just solved my own problem!
The third last line:
UserRangeOutput.Range("A1") = UserRangeInput
Should be:
UserRangeInput.Copy UserRangeOutput
Is that what you would have done?
Cheers
pvr928
Yeah, but I like to stick destination in the code since that makes it easier for me to remember what I was doing months later.
If you get stuck again post back.Code:UserRangeInput.Copy Destination:=UserRangeOutput
Bookmarks