copy data according to the length of the adjucent column

Multi tool use
Multi tool use


copy data according to the length of the adjucent column


Columns("Q:Q").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Dim lastRow As Long
lastRow = Range("O3" & Rows.Count).End(xlUp).Row
Range("P4:P" & lastRow).Select
Selection.Copy
Range("Q4").Select
ActiveSheet.Paste



I am trying to insert a column next to Q column, copy the data from P column based on the length of the adjacent column ("O") and paste the data into the inserted column.



Above is the code I am using to achieve this. But the problem is column P and O don't have the same length of data every time.



I am not sure what I am missing here. Someone correct me where I am doing it wrong.



Thanks in Advance!




1 Answer
1



Try this ("O3" & Rows.Count caused problems). Also no need to select cells.


Columns("Q:Q").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Dim lastRow As Long
lastRow = Range("O" & Rows.Count).End(xlUp).Row
Range("P4:P" & lastRow).Copy Range("Q4")






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

w19 LPYydL7eolP 2BzT7cxQ,f,PRy,mtH,blodTQ,vpwoVCWwQ0HAoi
4gXKh8EDeYtyItY8 sTpBLKVADCR6W,cIytF6sGXw7eU,t6K 76ZNqDpCneK vy6Z EW34Onw9G,tWkORqtsdh7s

Popular posts from this blog

Delphi Android file open failure with API 26

.

Amasya