Page Numbering Macro Code

austinandrei

Board Regular
Joined
Jun 7, 2014
Messages
117
Hi,
I have a set of data in Column A which varies from 1 to 1000, and there maybe more than 1000 line items.
Sample is below which only consist of 5 items, Row1 is always a header and is not counted:
ITEMEntity
1500249
2500249
3500249
4500249
5500249

<tbody>
</tbody>
What I need is to identify the pages in Column C, each page consist of 50items.
In example above, all are identified as "Page1" as it is only about 5items.
If it hits 60 items, the first 50 will be identified as "Page1" and the items from 51-60 will be identified as "Page2".
But if all the list items exceeds 1000, then all will be in error, no more paging.
1000 will be the limit of page identification.
Here's the simple code that will work for less criteria:
Code:
Sub PDFPage()


itemcount = Range("B" & Rows.Count).End(xlUp).Offset().row
pagenumber = 1


For paging = 2 To itemcount


If Range("A" & paging) > 50 Then
    Range("C" & paging).Value = "Page" & pagenumber
'Next ElseIf if it is 51-100 and so on and so on


End If


Next


End Sub

austin
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
you could try this
Code:
Sub PDFPage()
Dim count As Long
itemcount = Range("B" & Rows.count).End(xlUp).Offset().Row
pagenumber = 1
count = 1
For paging = 2 To itemcount
    If count > 50 Then
        count = 1
        pagenumber = pagenumber + 1
        Else
    End If
    Range("C" & paging).Value = "Page " & pagenumber
    count = count + 1
Next
End Sub
 
Upvote 0
Hi dermie
This great.
One last requirement, that if it hits 1000, if will no longer be Page1, Page2 and so on.it will automatically writes "ERROR", too many data.
Thanks!
 
Upvote 0
just above If count > 50 Then
put
Code:
if pagenumber = 3 then
    pagenumber = "ERROR"
    else
end if
 
Upvote 0
Hi Dermie,
The added code will just make the Page3 as pageError but all of it should be in error once the items are counted as 1000.
But I already found a way wherein before your codes, if itemcount is >1000, it won't run the codes but instead put "ERROR"
Code:
Sub PDFPage()
Dim count As Long
itemcount = Range("B" & Rows.count).End(xlUp).Offset().Row


pagenumber = 1
count = 1
For paging = 2 To itemcount
If itemcount > 1001 Then
    Range("C" & paging).Value = "ERROR"
Else
    If count > 50 Then
        count = 1
        pagenumber = pagenumber + 1
        Else
    End If
    Range("C" & paging).Value = "Page " & pagenumber
    count = count + 1
End If
Next


End Sub
Thanks a lot for your help!
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

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