Copy/Paste part of a variable Range

KB_Miner

Board Regular
Joined
Dec 5, 2013
Messages
119
I'm trying to set a range to a variable, then copy and paste the first three columns of that range to the right by one column. Thinking my syntax on the copy/paste is off slightly as the code errors out during the set statement of the CopyFrom variable. The WRange variable will be set by a select case based on a drop down list from a user form, but the copy/paste action should be consistent no matter which range is set to the WRange variable as it will always be a range 4 columns wide by 3 rows tall.

Here's my current code:

VBA Code:
Dim WRange As Range
Dim CopyFrom As Range, CopyTo As Range

Set WRange = Range("B15:E17")
Set CopyFrom = WRange(.Cells(1, 1), .Cells(3, 3))
Set CopyTo = WRange(.Cells(1, 2), .Cells(3, 4))
CopyFrom.Copy CopyTo
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try

VBA Code:
Dim WRange As Range
Dim CopyFrom As Range, CopyTo As Range

Set WRange = ThisWorkbook.ActiveSheet.Range("B15:E17")

Set CopyFrom = WRange.Range(WRange.Cells(1, 1), WRange.Cells(3, 3))
Set CopyTo = WRange.Range(WRange.Cells(1, 2), WRange.Cells(3, 4))

CopyFrom.Copy CopyTo
 
Upvote 0
Solution
@Cubist That worked. Knew my syntax for the CopyFrom/To lines was off, just couldn't seem to find a good answer from browsing the forums. Thanks for the help!
 
Upvote 0
@Cubist While your code got rid of my errors, it didn't actually work for copying and pasting my data. After some trial and error, I figured this out and it's working great.
VBA Code:
Set CopyFrom = WRange.Cells(1, 1).Resize(3, 3)
Set CopyTo = WRange.Cells(1, 2)
CopyFrom.Copy CopyTo
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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