Looping a macro until the last data row

95helsby

New Member
Joined
Jul 30, 2009
Messages
13
I have an excel problem related to running the same macro multiple times for data with one of the references changing each time.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
I need the macro to take a series of values from one spreadsheet (references G2, H2 and F2-F8), paste them into a second spreadsheet and also enter a couple of values into the second spreadsheet, then copy data from the second spreadsheet and paste it into the first (references E2, I2). The macro I have built successfully does this, but I then need the macro to be repeated, but with the references from the first spreadsheet changed to 7 rows further down (G9, H9, F9-15 then pasting into E9, I9) with the second spreadsheet references staying the same. This then needs to be repeated around 150 times, though each time it is run it will need to be run a different number of times. Is there a way of getting a macro to loop so that it changes one set of references, keeps the second set the same and keeps looping until it reaches the final row? (i.e. the row it reaches is blank)

Here's the code I have for the macro that currently works for the first set of data:

Sub Macro1()<o:p></o:p>
'<o:p></o:p>
Range("C16").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "N"<o:p></o:p>
Range("C17").Select<o:p></o:p>
Windows("Remodeling.xls").Activate<o:p></o:p>
Range("G2").Select<o:p></o:p>
Selection.Copy<o:p></o:p>
Windows("New Housing Model Transportation only.xls").Activate<o:p></o:p>
Range("C29").Select<o:p></o:p>
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _<o:p></o:p>
:=False, Transpose:=False<o:p></o:p>
Windows("Remodeling.xls").Activate<o:p></o:p>
Range("F2:F8").Select<o:p></o:p>
Application.CutCopyMode = False<o:p></o:p>
Selection.Copy<o:p></o:p>
Windows("New Housing Model Transportation only.xls").Activate<o:p></o:p>
Range("C34").Select<o:p></o:p>
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _<o:p></o:p>
:=False, Transpose:=False<o:p></o:p>
Sheets("Base").Select<o:p></o:p>
Application.CutCopyMode = False<o:p></o:p>
Selection.Copy<o:p></o:p>
Windows("Remodeling.xls").Activate<o:p></o:p>
Range("E2").Select<o:p></o:p>
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _<o:p></o:p>
:=False, Transpose:=False<o:p></o:p>
Selection.End(xlToRight).Select<o:p></o:p>
Application.CutCopyMode = False<o:p></o:p>
Selection.Copy<o:p></o:p>
Windows("New Housing Model Transportation only.xls").Activate<o:p></o:p>
Sheets("Summary").Select<o:p></o:p>
Range("H48").Select<o:p></o:p>
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _<o:p></o:p>
:=False, Transpose:=False<o:p></o:p>
Range("C16").Select<o:p></o:p>
Application.CutCopyMode = False<o:p></o:p>
ActiveCell.FormulaR1C1 = "Y"<o:p></o:p>
With Application<o:p></o:p>
.Iteration = True<o:p></o:p>
.MaxChange = 0.00001<o:p></o:p>
Range("c48").Goalseek Goal:=Range("H48"), ChangingCell:=Range("c47")<o:p></o:p>
Range("C54").Select<o:p></o:p>
Selection.Copy<o:p></o:p>
Windows("Remodeling.xls").Activate<o:p></o:p>
Range("I2").Select<o:p></o:p>
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _<o:p></o:p>
:=False, Transpose:=False<o:p></o:p>
Windows("New Housing Model Transportation only.xls").Activate<o:p></o:p>
End With<o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
<o:p>Thanks in advance for taking the time to look at this.</o:p>
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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