Creating a loop for a copy and paste function

matri00

New Member
Joined
May 25, 2011
Messages
1
I am very new to using macros (1st day today). I've managed to create a macro that produces the copy and paste function I want. I can't however manage to apply it to the whole spreadsheet, only the first row, I'm guessing I need some sort of loop. The cells in column A are merged to a varying degree, e.g some merged cells contain 4 rows, others may contain,3, or 5. I only want this macro applied to each merged cell from column A and the associated function I've already produced, not every row in the spreadsheet.

Here's what I've got so far:

Sub Macro4()
'
' Macro4 Macro
' Macro recorded 25/05/2011 by Rich
'


Dim mycell As Range
Set mycell = ActiveCell



mycell.Copy
mycell.Offset(0, 9).Select
ActiveSheet.Paste
mycell.Offset(0, 1).Select
Selection.Copy
mycell.Offset(0, 10).Select
ActiveSheet.Paste
mycell.Offset(0, 4).Select
Selection.Copy
mycell.Offset(0, 11).Select
ActiveSheet.Paste
mycell.Offset(0, 2).Select
Selection.Copy
mycell.Offset(0, 12).Select
ActiveSheet.Paste
mycell.Offset(0, 3).Select
Selection.Copy
mycell.Offset(0, 13).Select
ActiveSheet.Paste
mycell.Offset(0, 1).Offset(1, 0).Select
Selection.Copy
mycell.Offset(0, 14).Select
ActiveSheet.Paste
mycell.Offset(0, 4).Offset(1, 0).Select
Selection.Copy
mycell.Offset(0, 15).Select
ActiveSheet.Paste


mycell.Offset(0, 9).Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With

End Sub



Any help would be greatly appreciated, Cheers Rich
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,224,584
Messages
6,179,693
Members
452,938
Latest member
babeneker

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