PDA

View Full Version : Solved: repeat macro set number of times



jazznaura
10-12-2007, 10:33 AM
Hi all,
Need some help.
I recorded a simple macro to cut/paste and I need to repeat this 20 or so times. I could copy and paste the code over and over, but is there some simple code that will repeat code in a module a set number of times.
Looked at loops but my knowledge is not great and have had trouble understanding it. Is there a simple way, a couple of lines of code that say, “Go back to the start, and run this code another 19 times?”
Thanks

Norie
10-12-2007, 11:05 AM
Can we see the code?

And can you tell us what it actually meant to do?

jazznaura
10-12-2007, 11:35 AM
hi,
thanks for the response.

it simply moves 25 rows of data to a seperate sheet and prints, then deletes the data. i want it to repeat this so i can print 25 rows of data at a time(each printed page having the headers and titles in row 1). this is the only way i know how.



Sheets("SELECTS").Select
Range("A2:H27").Select
Selection.Cut
Sheets("Sheet1").Select
Range("A2").Select
ActiveSheet.Paste
Range("A2:H27").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1:H27").Select
Range("H27").Activate
Application.CutCopyMode = False
ActiveSheet.PageSetup.PrintArea = "$A$1:$H$27"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Range("A2:H27").Select
Range("H27").Activate
Selection.ClearContents
Range("A2").Select
Sheets("SELECTS").Select
Range("A2:H27").Select
Selection.EntireRow.Delete"


i have also attached my wookbook.
i know there is probably a better and more slick way of doing this, but my knowledge is not that good.

thanks again

Norie
10-12-2007, 12:13 PM
So basically you want to print chunks of 25 rows?

If so try this.

Sub Print25()
Dim wsSel As Worksheet
Dim LastRow As Long
Dim I As Long
Set wsSel = Worksheets("SELECTS")
LastRow = wsSel.Range("A" & Rows.Count).End(xlUp).Row

For I = 1 To LastRow Step 25
wsSel.PageSetup.PrintTitleRows = "1:1"
wsSel.PageSetup.PrintArea = Range("A2:H27").Offset(I).Address
wsSel.PrintOut Preview:=True

Next I

End Sub

Remove the print preview part - that's just for testing.

jazznaura
10-12-2007, 12:25 PM
thanks again for your time, will give it a go.