Loop thru Rows

Jenawade

Board Regular
Joined
Apr 8, 2002
Messages
231
This form (below) has some links to row 2 of our data sheet and is saved as 2011-250.xlsm. This is our 2nd out of 4 or 5 batch runs. I manually select rows 4-11 of this form, use the find/replace to change $2 to $3 for the links, save this as the next form number (2011-251.xlsm), then do it again through the end of the data. The data runs from row 2 through row 102, form 2011-250 through 2011-350. I know a macro could whip right through these in no time. If someone wouldn't mind putting one together for me I would be grateful!


 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi Jen,

If I'm understanding you correctly, you only need to change $2 to $3 in your Active Workbook,
then make 100 copies changing the file name for each.

If that is correct, then I'd suggest 2 separate macros:
The first to change the Row Number for your next batch and
the second to make the copies using SaveAs.

Code:
Sub Next_Batch_Run()
    With Sheets("RFMD Form").Rows("4:11")
       .Replace What:="$2", Replacement:="$3", LookAt:=xlPart
    End With
End Sub

Code:
Sub Make_Forms()
    Dim lngFileNr As Long
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
 
    For lngFileNr = 250 To 350
        ActiveWorkbook.SaveAs Filename:="2011-" & lngFileNr & ".xlsm", _
             FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
    Next lngFileNr
    Application.DisplayAlerts = True
End Sub

This approach lets you double-check that your Row Numbers were successfully changed
prior to making the committment to 100 copies! ;)

You can also make variations of Next_Batch_Run which would change $1 to $2, $3 to $4 etc.
 
Last edited:
Upvote 0
Hi Jen,

If I'm understanding you correctly, you only need to change $2 to $3 in your Active Workbook,
then make 100 copies changing the file name for each.

If that is correct, then I'd suggest 2 separate macros:
.

Thanks for the reply! :) I need to change the row number in the formulas each time as well as save as. So row $2 is saved as 2011-250, then I need to change the instances of $2 in the formulas to $3 and save as 2011-251, change them to $4 and save as 2011-252, to $5 and 2011-253, etc, through row $102 and file name 2011-350.
 
Upvote 0
Thanks for the clarification - I totally misunderstood that. :eeek:

Try....

Code:
Sub Make_Batch_Forms()
    Dim lngRowRef As Long, lngFileNr As Long
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
 
    With Sheets("RFMD Form").Rows("4:11")
        For lngRowRef = 2 To 102
            lngFileNr = lngRowRef + 248
            ActiveWorkbook.SaveAs Filename:="2011-" & lngFileNr & ".xlsm", _
                FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
           .Replace What:="$" & lngRowRef, Replacement:="$" & lngRowRef + 1, _
                LookAt:=xlPart
         Next lngRowRef
    End With
    ActiveWorkbook.Close SaveChanges:=False
    Application.DisplayAlerts = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,612
Messages
6,179,890
Members
452,948
Latest member
Dupuhini

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