Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Copy-Paste a Row via a cell reference

Hi,
Im trying to do something that is more advanced of my elementary VBA skills.
I would like to create a procedure (macro) that would copy Row 2 and paste
it according to the value in cell B2. (B2 being the row number to paste to).

IE: If B2 says 11. The macro would copy Row 2 , then paste to Row 11.
Row 2 will always be the Row that is copied. But the value in B2 can change
to another row reference.

Im just learning VBA for Excel and have figured out the Row(2) , Select,
Copy, Paste part. But not sure how to word the code as reference to B2. My
attempts have not worked.

Thank you for your time on this,
Amy

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy-Paste a Row via a cell reference

Sub copyRow2()
rows(2).copy Destination:=rows(Range("B2").value)
end sub

--
Regards,
Tom Ogilvy


"AMY Z." wrote in message
...
Hi,
I'm trying to do something that is more advanced of my elementary VBA

skills.
I would like to create a procedure (macro) that would copy Row 2 and paste
it according to the value in cell B2. (B2 being the row number to paste

to).

IE: If B2 says 11. The macro would copy Row 2 , then paste to Row 11.
Row 2 will always be the Row that is copied. But the value in B2 can

change
to another row reference.

I'm just learning VBA for Excel and have figured out the Row(2) , Select,
Copy, Paste part. But not sure how to word the code as reference to B2.

My
attempts have not worked.

Thank you for your time on this,
Amy



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Copy-Paste a Row via a cell reference

This will do it ----
Rows(2).Copy Destination:=Rows(Range("B2"))

but it would be worth putting a check that the value in B2 is numeric and in
range by using.....

With Range("B2")
If .Value 0 And .Value <= 65536 Then
Rows(2).Copy Destination:=Rows(.Value)
Else
MsgBox "Value of B2 is out of range"
End If
End With


--
Cheers
Nigel



"AMY Z." wrote in message
...
Hi,
I'm trying to do something that is more advanced of my elementary VBA

skills.
I would like to create a procedure (macro) that would copy Row 2 and paste
it according to the value in cell B2. (B2 being the row number to paste

to).

IE: If B2 says 11. The macro would copy Row 2 , then paste to Row 11.
Row 2 will always be the Row that is copied. But the value in B2 can

change
to another row reference.

I'm just learning VBA for Excel and have figured out the Row(2) , Select,
Copy, Paste part. But not sure how to word the code as reference to B2.

My
attempts have not worked.

Thank you for your time on this,
Amy



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Copy-Paste a Row via a cell reference

Thank you Tom and Nigel for taking time to answer my question.
It works great!

If you come back here. I have a another question. The "Destination" part of
the code... is that what is called a method or maybe a property?

I'm just beginning to learn.
Thanks again if you come back to this post.
Amy

"AMY Z." wrote:

Hi,
Im trying to do something that is more advanced of my elementary VBA skills.
I would like to create a procedure (macro) that would copy Row 2 and paste
it according to the value in cell B2. (B2 being the row number to paste to).

IE: If B2 says 11. The macro would copy Row 2 , then paste to Row 11.
Row 2 will always be the Row that is copied. But the value in B2 can change
to another row reference.

Im just learning VBA for Excel and have figured out the Row(2) , Select,
Copy, Paste part. But not sure how to word the code as reference to B2. My
attempts have not worked.

Thank you for your time on this,
Amy

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Copy-Paste a Row via a cell reference

Hi Amy

Destination as it is used here is an Argument of the Copy Method.

Hope that clears it up <g
Rowan

AMY Z. wrote:
Thank you Tom and Nigel for taking time to answer my question.
It works great!

If you come back here. I have a another question. The "Destination" part of
the code... is that what is called a method or maybe a property?

I'm just beginning to learn.
Thanks again if you come back to this post.
Amy

"AMY Z." wrote:


Hi,
Im trying to do something that is more advanced of my elementary VBA skills.
I would like to create a procedure (macro) that would copy Row 2 and paste
it according to the value in cell B2. (B2 being the row number to paste to).

IE: If B2 says 11. The macro would copy Row 2 , then paste to Row 11.
Row 2 will always be the Row that is copied. But the value in B2 can change
to another row reference.

Im just learning VBA for Excel and have figured out the Row(2) , Select,
Copy, Paste part. But not sure how to word the code as reference to B2. My
attempts have not worked.

Thank you for your time on this,
Amy



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How will hyperlink cell reference update after copy paste? bjry Excel Worksheet Functions 2 May 12th 09 05:10 PM
Copy & Paste Forumla - but reference cell is changing Andy Excel Discussion (Misc queries) 5 October 12th 07 04:41 PM
copy-paste started misbehaving (cell reference wrong) [email protected] Excel Discussion (Misc queries) 1 April 17th 07 07:09 AM
Reference an identical cell on a different page using copy/paste? Radar Excel Worksheet Functions 4 August 29th 05 05:21 PM
Copy and Paste macro needs to paste to a changing cell reference loulou Excel Programming 0 February 24th 05 10:29 AM


All times are GMT +1. The time now is 12:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"