Copy and Pasting Loop

Lyrad39

New Member
Joined
Jun 14, 2023
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
Good day Community,

I am intending to loop and copy the tables (K4:T20) as well as other tables on the right till the end, pasting them below row 20 and so on. However, I am stuck with the loop code and I hope to seek your help with it. Attached photo as shown for example.

These are the codes gotten with recording but I am unable to figure it out:

VBA Code:
Sub Macro4()
'
' Macro4 Macro
'

'
    Range("K4:T20").Select
    Selection.Cut
    ActiveWindow.SmallScroll Down:=3
    Range("A21").Select
    ActiveSheet.Paste
    Range("U4:AD20").Select
    Selection.Cut
    ActiveWindow.SmallScroll Down:=15
    Range("A38").Select
    ActiveSheet.Paste
End Sub
 
Last edited by a moderator:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Attached as shown.
 

Attachments

  • Capture.PNG
    Capture.PNG
    73.7 KB · Views: 11
Upvote 0
Welcome to the MrExcel board!

When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊

Does this do what you want? If not, more details please.
Test with a copy of your workbook.

VBA Code:
Sub MoveTables()
  Dim Lastcol As Long, c As Long
  
  Lastcol = Cells.Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
  For c = 11 To Lastcol Step 10
    Cells(4, c).Resize(17, 10).Cut Destination:=Range("C" & Rows.Count).End(xlUp).Offset(1, -2)
  Next c
End Sub
 
Upvote 1
Thank you for the help Peter, appreciate it! All seems good except the last coloumn of results for Sd was shifting down to the left on column A instead and it was shifted down by one table starting from A19.
 

Attachments

  • Capture1.PNG
    Capture1.PNG
    44.7 KB · Views: 8
Upvote 0
Can't tell anything from the picture. Can you post the original sample data with XL2BB so that I can copy it to test with?
 
Upvote 1
My apologies Peter but my workplace does not allow installation of add-ins. I have attached the proper screenshots of before VS after. Thank you so much for the help.
 

Attachments

  • Capture.PNG
    Capture.PNG
    73.7 KB · Views: 5
  • Capture3.PNG
    Capture3.PNG
    79.4 KB · Views: 6
Upvote 0
Not following the images. Original sample data (post 2 image) had that first #REF! in cell A4. My code was based on that and left the first table where it was and moved moved all the other tables below that first one on the same sheet.
Your 'before' image now still shows that first #REF! in cell A4. Your 'after' image shows that first #REF! in cell B3. Have you altered the code in some way?
 
Upvote 1
Ohh yes I did some adjustments, I have revert it and the codes work now awesome!! Would you know how I could delete the rows for "John David Saly...." and just paste the results?
 

Attachments

  • Capture4.PNG
    Capture4.PNG
    58.7 KB · Views: 9
Upvote 0
Would you know how I could delete the rows for "John David Saly...." and just paste the results?
Try

VBA Code:
Sub MoveTables_v2()
  Dim Lastcol As Long, c As Long
  
  Lastcol = Cells.Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
  For c = 11 To Lastcol Step 10
    Cells(5, c).Resize(16, 10).Cut Destination:=Range("C" & Rows.Count).End(xlUp).Offset(1, -2)
  Next c
  ActiveSheet.UsedRange.Offset(, 10).ClearContents
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,215,588
Messages
6,125,692
Members
449,250
Latest member
azur3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top