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

D

dhstein

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.
 
G

Gary''s Student

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
 
D

dhstein

Gary''s Student said:
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

Thanks Rick. That did the trick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top