Copy range defined by cell contents (probably quick solution)

hartsie

Board Regular
Joined
May 6, 2020
Messages
77
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

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,526
Office Version
  1. 365
Platform
  1. Windows
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
 

hartsie

Board Regular
Joined
May 6, 2020
Messages
77
Office Version
  1. 2016
Beautiful! Bravo! You are a very good problem solver. Thank you!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,526
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

hartsie

Board Regular
Joined
May 6, 2020
Messages
77
Office Version
  1. 2016
@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:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,526
Office Version
  1. 365
Platform
  1. Windows
Glad you sorted it & thanks for letting us know.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,483
Messages
5,636,603
Members
416,928
Latest member
ezmeng

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
Top