Hi folks, I am trying to write some VB code that allows the user to select a range via an input box, then copy that range and paste it into a different worksheet.
The code I have written allows the selection OK, but I can't get it to paste into the correct position in the other worksheet. What is supposed to happen is the code finds the next blank row and then pastes the selection underneath. It the moment it pastes into whatever cell was last selected.
Can anybody help?
Sub GetRange()
Dim oRangeSelected As Range
Dim NextRow As Long
Dim LastRow As Long
On Error Resume Next
Sheets("Data").Activate
Set oRangeSelected = Application.InputBox("Please select a range of cells!", _
"Select A Range", Selection.Address, , , , , 8)
If oRangeSelected Is Nothing Then
MsgBox "It appears as if you pressed cancel!"
Else
Range(oRangeSelected).Select
Selection.Copy
Sheets("Sampled Data Summary").Activate
NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
With Sheets("Sampled Data Summary")
Range("A3").Select
Cells(3, 1) = ActiveSheet.Paste
End With
End If
End Sub
The code I have written allows the selection OK, but I can't get it to paste into the correct position in the other worksheet. What is supposed to happen is the code finds the next blank row and then pastes the selection underneath. It the moment it pastes into whatever cell was last selected.
Can anybody help?
Sub GetRange()
Dim oRangeSelected As Range
Dim NextRow As Long
Dim LastRow As Long
On Error Resume Next
Sheets("Data").Activate
Set oRangeSelected = Application.InputBox("Please select a range of cells!", _
"Select A Range", Selection.Address, , , , , 8)
If oRangeSelected Is Nothing Then
MsgBox "It appears as if you pressed cancel!"
Else
Range(oRangeSelected).Select
Selection.Copy
Sheets("Sampled Data Summary").Activate
NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
With Sheets("Sampled Data Summary")
Range("A3").Select
Cells(3, 1) = ActiveSheet.Paste
End With
End If
End Sub