Automatic list creating - start at the beginning of new page (macro)

lastknownuser

New Member
Joined
Feb 1, 2022
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Started very recently with VBA so I'm not an expert but I am familiar with programming in other languages.
I want to create a macro to write a number of names and it would create list (by copying template on the side), and the problem is after row 50, 100,... How can I define that on new page it starts at 51 as first row? I attached the pictures. So the problem is splitting of copied range as can be seen in picture, I don't want that

Any help would be welcome, especially if there are more examples of this kind of template creating for print, thank you
Current short code:
VBA Code:
Sub test()

Range("J1:R5").Select
Selection.Copy
Dim ink As Integer
Dim i As Integer
i = 1
ink = InputBox("Enter number of names")
ink2 = ink * 6
For i = 1 To ink2 Step 6
Worksheets("sheet1").Cells(i, 1).Select
ActiveSheet.Paste

Next i

End Sub

test123.png
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You said:
How can I define that on new page

Do you mean Page like pages when you print this out or do you mean new sheet Like worksheet
 
Upvote 0
This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
My idea was to define conditions, like when ink2 is between 50 and 100, star at row 51 and so on. But I don't know how to define conditions withing for loop in VBA. I tried with some using IF and WHILE but it didn't work
 
Upvote 0
I know how to do loops but not how to install page Breaks
I've never done that,
 
Upvote 0
I know how to do loops but not how to install page Breaks
I've never done that,
I don't really need page breaks, here is the code of my loop, I can't figure out why it is an endless loop, it just doesn't stop, maybe you could help

VBA Code:
Do While i < ink2

If i < 45 Then
Worksheets("sheet1").Cells(i, 1).Select
ActiveSheet.Paste
Else
i = 51
End If

If 50 < i < 100 Then
Worksheets("sheet1").Cells(i, 1).Select
ActiveSheet.Paste
End If

i = i + 6

Loop
 
Upvote 0
Tell me in words what you're trying to do. Your copying cells and then saying activesheet.paste

Where on the active sheet are you wanting to paste it.
We should be using sheet names like what is the name of the sheet where you're copying from and what is the name of the sheet you're wanting to paste to.
 
Upvote 0
This line will always return TRUE If 50 < i < 100 Thenwhich is why you get an infinite loop.
Try it like
VBA Code:
If i > 50 And i < 100 Then
 
Upvote 0
And your images seem to be showing 4 sheets that say add header and add footer.
What is that all about
 
Upvote 0

Forum statistics

Threads
1,215,385
Messages
6,124,626
Members
449,174
Latest member
Anniewonder

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