0

Help needed. I'm a newbie to VBA and trying to start with simple macro. But even with that failing miserably. All i'm trying to do is copy and paste from one worksheet to another using an input box to specify the range to be copied. Now I know for the input box is:

Application.InputBox("Enter the range from which you want to copy : ", Type:=8)

But what do line do i need in order to copy to a cell in another worksheet?

I apologise in advance for being an idiot.

2
  • range("A1").copy range("A2") (this copies A1 to A2) Commented Feb 4, 2013 at 17:28
  • Thanks for reply Sean. Will this not copy what is in A1 to A2. What i need is a macro that allows me to specify a range using the input box. However i need the range specified to be copied to another worksheet. In this instance worksheet is called "weekly raw" Commented Feb 4, 2013 at 17:37

3 Answers 3

2

Is this what you are trying?

Option Explicit

Sub Sample()
    Dim rngCopyFrom As Range

    On Error Resume Next
    Set rngCopyFrom = Application.InputBox("Enter the range from which you want to copy", Type:=8)
    On Error GoTo 0

    If Not rngCopyFrom Is Nothing Then
        '~~> Copy the range to say Cell A1 of Sheets("weekly raw")
        rngCopyFrom.Copy ThisWorkbook.Sheets("weekly raw").Range("A1")
    End If
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Siddharth. Yes that's what I needed.
1

One way to do it is like this:

Sub CopyRange()
    Dim FromRange As Range
    Dim ToRange As Range

    Set FromRange = Application.InputBox("Enter the range from which you want to copy : ", Type:=8)
    Set ToRange = Application.InputBox("Enter the range to where you want to copy : ", Type:=8)

    FromRange.Copy ToRange
    'Or you can do it like this if you need some flexibility on Paste 
    'FromRange.Copy
    'ToRange.PasteSpecial xlPasteValues, xlPasteSpecialOperationNone
End Sub

Comments

0

Here's some sample code:

Option Explicit

Sub CopyStuff()

Dim x As Range
Dim y As Range

Set x = Application.InputBox("Select what copy using the mouse", Type:=8)
Set y = ActiveWorkbook.Sheets("Sheet2").Range("A1")

x.Copy y

End Sub

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.