How to loop a macro

rlcurlee

New Member
Joined
Aug 1, 2014
Messages
6
I have a macro that copies cells to another sheet and puts cells in order. I need to make this marco loop until there are no more rows to copy. This macro was recorded. I'm not good at writing macro from scratch.

I can't download the XL2BB so I hope you can us my macro.



Code:
Sub COPY_MOC()
'
' COPY_MOC Macro
'
' Keyboard Shortcut: Ctrl+Shift+Q
'
    Range("A2").Select
    Sheets("Sheet1").Select
    Range("B2:B5").Select
    Selection.Copy
    Sheets("Sheet2").Select
    Range("A2").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    Range("E2").Select
    Sheets("Sheet1").Select
    Range("D2:D5").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Sheet2").Select
    Range("E2").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    Rows("2:2").Select
    Application.CutCopyMode = False
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("A2").Select
    Sheets("Sheet1").Select
    Rows("1:5").Select
    Selection.Delete Shift:=xlUp
    Sheets("Sheet2").Select
    Range("A2").Select
End Sub
 

Attachments

  • looping macro sheet2.PNG
    looping macro sheet2.PNG
    35.4 KB · Views: 10
  • looping macro.PNG
    looping macro.PNG
    36.8 KB · Views: 10

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
See if this works for you.
VBA Code:
Sub rlcurlee()
Dim LR As Long
LR = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("Sheet1").Activate
Range("A2").Select
Do While ActiveCell <> ""
    Range("B2:B5").Copy
    Sheets("Sheet2").Range("A" & LR).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    Range("D2:D5").Copy
    Sheets("Sheet2").Range("E" & LR).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    ''Rows("2:2").Select
    Application.CutCopyMode = False
    Rows("1:5").Delete Shift:=xlUp
    LR = LR + 1
Loop
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,072
Messages
6,122,968
Members
449,095
Latest member
Mr Hughes

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