Copy range defined by cell contents (probably quick solution)

hartsie

Board Regular
Joined
May 6, 2020
Messages
84
Office Version
  1. 2016
I am trying to keep a file short and simple. I have basically defined the cell ranges in multiple cells, and I am trying to use VBA to automate copying and pasting values among sheets, using the cell ranges I have already defined. For example, within Sheet2, I have defined a range in Sheet1 from which I want to copy a range of data. So, we will say that in Sheet2, I have input into a cell the text "A1:BC1," which represents the range on Sheet1 from where I want to copy data. So, from Sheet2, I want to go to Sheet1, select the range of data (defined in Sheet2, "A1:BC1"), and paste it to Sheet3.

I have tried defining the range "A1:BC1" as a string. My simple VBA, which isn't working out for me right now, and its costing enough of my time that I am ready to call it quits, is below:

Dim CopRng As String

Sheets("Sheet2").Select
Range(Range("D6").Value = CopRng
Sheets("Sheet1").Activate
CopRng.Select


I can't seem to get to the point where I can define the range, and then select it. It has been a while since I have touched VBA and I am pulling my hair out trying to do something that I thought would be SO. SIMPLE.

I understand that I know very little about VBA. I thought this would be an easy task, but its proving to best me at every turn. I have scoured the interwebs, but apparently my search keywords aren't specific enough to find an answer.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
How about something like
VBA Code:
Sub hartsie()
   Dim CopyRng As Range
   
   With Sheets("Sheet2")
      Sheets("Sheet1").Range(.Range("D6").Value).Copy Sheets("Sheets3").Range(.Range("D6").Value)
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
@Fluff

UPDATE - I fixed it.

Sheets("Sheet1").Range(.Range("D6").Value).Copy Sheets("Sheets3").Range(.Range("D6").Value)

Do you know why I would get a 1004 error? It worked the first time around and now it is yelling at me.

'Select Method of Range Class Failed'
 
Last edited:
Upvote 0
Glad you sorted it & thanks for letting us know.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,267
Members
449,075
Latest member
staticfluids

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