Copy and paste cells until reach end of data
Closed
Beksta
-
Apr 14, 2010 at 01:33 PM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Apr 15, 2010 at 12:53 PM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Apr 15, 2010 at 12:53 PM
Related:
- Copy and paste cells until reach end of data
- Tmobile data check - Guide
- Gta 5 data download for pc - Download - Action and adventure
- Amd data change update new data to dmi ✓ - Windows 10 Forum
- Transfer data from one excel worksheet to another automatically - Guide
- Digital data transmission - Guide
9 responses
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Apr 14, 2010 at 03:20 PM
Apr 14, 2010 at 03:20 PM
Sub pasteCells() Dim lMaxRows As Long ' max rows of data Dim lRowBeanCounter As Long ' to count row Dim lTargetRow As Long lMaxRows = Cells(Rows.Count, "A").End(xlUp).Row For lRowBeanCounter = 1 To lMaxRows Step 20 lTargetRow = lTargetRow + 1 With Sheet2 .Cells(lTargetRow, "K") = Cells(1 + (lTargetRow - 1) * 20, "A") .Cells(lTargetRow, "L") = Cells(7 + (lTargetRow - 1) * 20, "B") .Cells(lTargetRow, "M") = Cells(9 + (lTargetRow - 1) * 20, "B") .Cells(lTargetRow, "N") = Cells(10 + (lTargetRow - 1) * 20, "B") End With Next lRowBeanCounter End Sub
Thank you for your help. It looks good but when I try to run the program i am given an error '424' object required. Can anyone help me with that?
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Apr 15, 2010 at 11:54 AM
Apr 15, 2010 at 11:54 AM
It will give you option of debug, See what line it highlight. Also could you please upload a sample file on some shared site like https://authentification.site and post back here the link.
Thank you rizvisa1
the data is uploaded here is the link:
https://authentification.site/files/21957132/data_sample.xlsx
the line that is highlighted is:
.Cells(lTargetRow, "K") = Cells(1 + (lTargetRow - 1) * 20, "A")
the data is uploaded here is the link:
https://authentification.site/files/21957132/data_sample.xlsx
the line that is highlighted is:
.Cells(lTargetRow, "K") = Cells(1 + (lTargetRow - 1) * 20, "A")
Didn't find the answer you are looking for?
Ask a question
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Apr 15, 2010 at 12:11 PM
Apr 15, 2010 at 12:11 PM
Add a new sheet names Sheet2
If you want on the same sheet then use this code
If you want on the same sheet then use this code
Sub pasteCells() Dim lMaxRows As Long ' max rows of data Dim lRowBeanCounter As Long ' to count row Dim lTargetRow As Long On Error Resume Next lMaxRows = Cells(Rows.Count, "A").End(xlUp).Row For lRowBeanCounter = 1 To lMaxRows Step 20 lTargetRow = lTargetRow + 1 Cells(lTargetRow, "K") = Cells(1 + (lTargetRow - 1) * 20, "A") Cells(lTargetRow, "L") = Cells(7 + (lTargetRow - 1) * 20, "B") Cells(lTargetRow, "M") = Cells(9 + (lTargetRow - 1) * 20, "B") Cells(lTargetRow, "N") = Cells(10 + (lTargetRow - 1) * 20, "B") Next lRowBeanCounter End Sub
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Apr 15, 2010 at 12:21 PM
Apr 15, 2010 at 12:21 PM
I used your file and added the macro and ran it without any issue
See if you can spot what is different between your file and this updated file
https://authentification.site/files/21957442/data_sample.xlsm
See if you can spot what is different between your file and this updated file
https://authentification.site/files/21957442/data_sample.xlsm
the first version did not have - on error resume next - it seems to be working now.
thank you so much, you have been extremely helpful. and have saved me so much frustration!
thank you so much, you have been extremely helpful. and have saved me so much frustration!
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Apr 15, 2010 at 12:53 PM
Apr 15, 2010 at 12:53 PM
On error resume next is not needed and should not be there either as there is no reason for error to occur. If an error does occur, it needs to be addressed. It was just an oversight on my part. I just re-ran the code without that line and it runs fine.