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:
You're welcome. Thanks for the confirmation. :)
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Good day Peter,

Would you know how I could adjust the codes to allow me to copy down the tables without following the format provided above?

Thank you.
 
Upvote 0
Not quite sure that I understand. If this is not what you want please clarify with example and/or reference to the original sample data.

VBA Code:
Sub MoveTables_v3()
  Dim Lastcol As Long, c As Long
  
  Application.ScreenUpdating = False
  Columns("A:J").Insert
  Lastcol = Cells.Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
  For c = 11 To Lastcol Step 10
    Cells(5, c).Resize(16, 10).Copy
    Range("C" & Rows.Count).End(xlUp).Offset(1, -2).PasteSpecial xlPasteValues
  Next c
  ActiveSheet.UsedRange.Offset(, 10).Clear
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Sorry I meant what if my tables are starting from row 20 instead of row 4 as shown in the photo, how should I edit the codes to have it copy and paste from row 20 instead.
 

Attachments

  • Capture.PNG
    Capture.PNG
    73.7 KB · Views: 7
Upvote 0
Sorry I meant what if my tables are starting from row 20 instead of row 4 ... how should I edit
Rich (BB code):
Sub MoveTables_v2a()
  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(21, 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

Forum statistics

Threads
1,215,586
Messages
6,125,689
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