I'm wanting to select a range of cells from one worksheet, push a button, have the user select cells on another sheet in a different workbook, and have the copied cells paste there.
I have the following code:
Private Sub btnCopyPaste_Click()
Dim CopyWS As Worksheet
Set CopyWS = ActiveWorkbook.Sheets("CopySheet")
Dim rngMyRange As Range
If TypeName(Selection) = "Range" Then
Set rngMyRange = Selection
Dim sCell As String
sCell = Range(Application.InputBox(Prompt:="Pick the Cell", Type:=8)).Value
rngMyRange.Copy .Range(sCell) 'this is the bad line
Else
Exit Sub
End If
End Sub
I'm trying to user an Application.InputBox to get the "cell to paste in" from the user, but I'm having trouble getting the relevant information about the cell back. Like, the workbook/worksheet location.
When I run the code and select the "cell to paste in" when prompted, the input box on the form shows this: '[WorkbookName]SheetName'!$A$1 ..
Is this information stored in the background, so that I can access it with a command, or will I have to take this string and dissect it?
Thank you for your help!
Application.InputBox
docs, specifically the paragraph that begins "If Type is 8, InputBox returns a Range object...", and the example immediately following. In fewer words - you should work with aRange
object, not aString
. – BigBen.Value
member call will fail if the user cancels that prompt. – Mathieu Guindon