Private Sub CommandButton1_Click()
'For copy range:
Dim CopyRange As Range
Dim CopySizeX As Long
Dim CopySizeY As Integer
'For paste range:
Dim PasteSheet As Worksheet
Dim PasteRange As Range
'For looping:
Dim i As Integer
'Prompt user for range to copy
SetCopyRange:
On Error Resume Next
Set CopyRange = Application.InputBox( _
Prompt:="Select cell(s) to copy:", _
Default:=ActiveWindow.RangeSelection.CurrentRegion.Address, _
Type:=8)
On Error GoTo 0
'Exit if input box cancelled
If CopyRange Is Nothing Then Exit Sub
'If non-contiguous range selected
If CopyRange.Areas.Count > 1 Then
MsgBox _
Prompt:="Selection must be contiguous.", _
Buttons:=vbExclamation
Set CopyRange = Nothing
GoTo SetCopyRange
End If
'Determine size of CopyRange
CopySizeX = CopyRange.Rows.Count
CopySizeY = CopyRange.Columns.Count
'Set sheet for pasting to.
'Amend as necessary...
Set PasteSheet = ThisWorkbook.Worksheets("Sheet2")
With PasteSheet
'Determine first empty column in PasteSheet
For i = 1 To .Columns.Count
If Application.WorksheetFunction.CountA(.Columns(i)) = 0 Then
Exit For
End If
Next i
'Set range for pasting to
Set PasteRange = .Cells(1, i).Resize(CopySizeX, CopySizeY)
End With
'Paste CopyRange into PasteRange
CopyRange.Copy Destination:=PasteRange
CopyRange.ClearContents
'Activate PasteSheet and
'select PasteRange...
PasteSheet.Activate
PasteRange.Select
End Sub