ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Conditional select and paste (https://www.excelbanter.com/excel-programming/347207-conditional-select-paste.html)

BrianDP1977[_5_]

Conditional select and paste
 

I have a range of data (C4:K6) named Data_1. I would like to create code
that will go through this range (or any defined range) and copy the
first two rows of this data to two different rows on the sheet (let's
say these rows are defined by the range C85:K86 and named
Data_1_1st_2rows). However, I don't just need the data pasted to this
range. I need the entire frist two rows of Data_1 pasted into the rows
comprising Data_1_1st_2rows. Thanks.


--
BrianDP1977
------------------------------------------------------------------------
BrianDP1977's Profile: http://www.excelforum.com/member.php...o&userid=29110
View this thread: http://www.excelforum.com/showthread...hreadid=490366


Greg Wilson

Conditional select and paste
 
Try:

Sub TransferData()
Dim r1 As Range, r2 As Range
Set r1 = Range("Data_1").Resize(2, Columns.Count)
Set r2 = Range("Data_1_1st_2Rows").Resize(2, Columns.Count)
r2.Value = r1.Value
End Sub

Regards,
Greg

"BrianDP1977" wrote:


I have a range of data (C4:K6) named Data_1. I would like to create code
that will go through this range (or any defined range) and copy the
first two rows of this data to two different rows on the sheet (let's
say these rows are defined by the range C85:K86 and named
Data_1_1st_2rows). However, I don't just need the data pasted to this
range. I need the entire frist two rows of Data_1 pasted into the rows
comprising Data_1_1st_2rows. Thanks.


--
BrianDP1977
------------------------------------------------------------------------
BrianDP1977's Profile: http://www.excelforum.com/member.php...o&userid=29110
View this thread: http://www.excelforum.com/showthread...hreadid=490366



BrianDP1977[_6_]

Conditional select and paste
 

Doesn't seem to work. Here's how I have it posted:


Code:
--------------------
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r1 As Range, r2 As Range
Set r1 = Range("Ext_DP6_P1_all").Resize(2, Columns.Count)
Set r2 = Range("Trunc_DP6_P1").Resize(2, Columns.Count)
r2.Value = r1.Value
End Sub
--------------------


--
BrianDP1977
------------------------------------------------------------------------
BrianDP1977's Profile: http://www.excelforum.com/member.php...o&userid=29110
View this thread: http://www.excelforum.com/showthread...hreadid=490366


Greg Wilson

Conditional select and paste
 
Sorry, I misread the range definitions. Try:

Sub TransferData()
Dim r1 As Range, r2 As Range
Set r1 = Range("Data_1").Resize(2).EntireRow
Set r2 = Range("Data_1_1st_2Rows").EntireRow
r2.Value = r1.Value
End Sub

Regards,
Greg



BrianDP1977[_7_]

Conditional select and paste
 

That works great. Thank you very much

--
BrianDP197
-----------------------------------------------------------------------
BrianDP1977's Profile: http://www.excelforum.com/member.php...fo&userid=2911
View this thread: http://www.excelforum.com/showthread.php?threadid=49036



All times are GMT +1. The time now is 08:14 AM.

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