Copy/Paste Special Macro

3LeggedDog

Board Regular
Joined
Feb 11, 2006
Messages
149
Hi,
I'm trying to figure out a macro. There would be a certain range in one sheet, and then, depending on a value given by the user in a dialogue box (with the value being either 1 or 2), that range would then be paste/special/values into one of two spots on a different sheet.

So, for example, I may have range Sheet1!$A$1:$D$5. If the user inputs 1, that range would be copy/paste special/values into Sheet2!$E$1:$H$5, and if the user inputs 2, it would be copy/paste special/values into Sheet2!$A$6:$D$10.

If anybody knows where to start on that, I'd appreciate it.

Thanks,
3LD
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Here's one way:
Code:
Sub ChoosePastePosition()
Dim r As Long, Rng As Range

Set Rng = Sheets("Sheet1").Range("A1:D5")
r = Application.InputBox("Paste data into range 1 or range 2? (enter 1 or 2 only)", "Select range 1 or 2")

    Select Case r
        Case 1
            Rng.Copy Sheets("Sheet2").Range("E1")
        Case 2
            Rng.Copy Sheets("Sheet2").Range("A6")
        Case Else
            MsgBox "Invalid entry, aborting."
    End Select
End Sub
 
Upvote 0
This is great, the only issue is that I need it to do a "Paste Special-Values" rather than just a Paste. Does anyone know what would need to be changed to do that?

Thanks,
3LD
 
Upvote 0
Code:
Sub ChoosePastePosition()
Dim r As Long, Rng As Range

Set Rng = Sheets("Sheet1").Range("A1:D5")
r = Application.InputBox("Paste data into range 1 or range 2? (enter 1 or 2 only)", "Select range 1 or 2")

    Select Case r
        Case 1
            Rng.Copy 
            Sheets("Sheet2").Range("E1").PasteSpecial xlPasteValues
        Case 2
            Rng.Copy 
            Sheets("Sheet2").Range("A6").PasteSpecial xlPasteValues
        Case Else
            MsgBox "Invalid entry, aborting."
    End Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,102
Messages
6,128,849
Members
449,471
Latest member
lachbee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top