ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Using a cell in the worksheet as a range in a VBA routine (https://www.excelbanter.com/excel-discussion-misc-queries/212311-using-cell-worksheet-range-vba-routine.html)

dhstein

Using a cell in the worksheet as a range in a VBA routine
 
I'm trying to copy some data from another file into my worksheet. I have the
data copied into a new sheet but now I need to cut and paste from the range
in the new sheet into the range in another sheet. I have a cell - e.g. K5
which I've created that has the range e.g. "A43122:D44367" - those values
are created based on the data that got copied. I can also break it up to get
any of those values in a cell so I could have K6 contents of 43122 for
example. I need to understand how to use those cell contents in VBA to copy
paste a range - I can't hard code the value 43122 - I have to get it from K6.
So I'm not clear on the syntax for something like this. Specifically, what
is the VBA loop or statement to copy that range to another location. Thanks
for any help.

Gary''s Student

Using a cell in the worksheet as a range in a VBA routine
 
Say A1 contains the text:
D2:E4

and A2 contains the text:
I1

we want the macro to use the contents of these two cells to define the
copy/paste

Sub copy_it()
Range(Range("A1").Value).Copy Range(Range("A2").Value)
End Sub
--
Gary''s Student - gsnu200817


"dhstein" wrote:

I'm trying to copy some data from another file into my worksheet. I have the
data copied into a new sheet but now I need to cut and paste from the range
in the new sheet into the range in another sheet. I have a cell - e.g. K5
which I've created that has the range e.g. "A43122:D44367" - those values
are created based on the data that got copied. I can also break it up to get
any of those values in a cell so I could have K6 contents of 43122 for
example. I need to understand how to use those cell contents in VBA to copy
paste a range - I can't hard code the value 43122 - I have to get it from K6.
So I'm not clear on the syntax for something like this. Specifically, what
is the VBA loop or statement to copy that range to another location. Thanks
for any help.


dhstein

Using a cell in the worksheet as a range in a VBA routine
 


"Gary''s Student" wrote:

Say A1 contains the text:
D2:E4

and A2 contains the text:
I1

we want the macro to use the contents of these two cells to define the
copy/paste

Sub copy_it()
Range(Range("A1").Value).Copy Range(Range("A2").Value)
End Sub
--
Gary''s Student - gsnu200817


"dhstein" wrote:

I'm trying to copy some data from another file into my worksheet. I have the
data copied into a new sheet but now I need to cut and paste from the range
in the new sheet into the range in another sheet. I have a cell - e.g. K5
which I've created that has the range e.g. "A43122:D44367" - those values
are created based on the data that got copied. I can also break it up to get
any of those values in a cell so I could have K6 contents of 43122 for
example. I need to understand how to use those cell contents in VBA to copy
paste a range - I can't hard code the value 43122 - I have to get it from K6.
So I'm not clear on the syntax for something like this. Specifically, what
is the VBA loop or statement to copy that range to another location. Thanks
for any help.


Thanks Rick. That did the trick.




All times are GMT +1. The time now is 11:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com