Page numbers in a cell

Bob W

New Member
Joined
Apr 17, 2002
Messages
6
I have over 200 work sheets in a workbook and I need to number them. I would like to add some code that will number them automatically into a cell on each worksheet. I would also like to have them numbered automatically if I add a worksheet or simply renumber the entire workbook each time I add a worksheet.

Any ideas on how I can do this?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try putting the following code in the declarations for ThisWorkbook:
Code:
Private Sub Workbook_NewSheet(ByVal Sh As Object)
For Each Sh In Worksheets
Sh.[a1].Value = Sh.Index
Next
End Sub
 
Upvote 0
Hi Al,
Tried the code. I wasn't able to get it to work. I'm not sure if I'm doing something wrong or not but I do come up with Sub error message.


On 2002-04-18 07:51, Al Chara wrote:
Try putting the following code in the declarations for ThisWorkbook:
Code:
Private Sub Workbook_NewSheet(ByVal Sh As Object)
For Each Sh In Worksheets
Sh.[a1].Value = Sh.Index
Next
End Sub
 
Upvote 0
I ran Al's bit of code and it worked fine...
Where are you placing your code?
Tom
 
Upvote 0
I started the visual basic editor and placed in there.

I'm not sure if this was the correct place.

Please advise if this was wrong and where to place the code. I'm a newbie.
Thanks

On 2002-04-23 05:19, TsTom wrote:
I ran Al's bit of code and it worked fine...
Where are you placing your code?
Tom
 
Upvote 0
I got it to work once and I'm not sure how I did it but now I can get it to work at all. So I know the code works I just need to know what steps to take to make it work consistently.

Can someone coach me through from beginning to end on what to do to place this code in a spreadsheet and make it work such as what things to open what to click, you know, the whole nine yards.

Thanks.

Bob
This message was edited by Bob W on 2002-04-23 08:39
 
Upvote 0
Sure.
From your standard Excel window, right-click on the Excel icon located in the upper-left-hand side of your screen(Directly left of the menu item(File), choose view code.
This will place you in the Workbook Class code module window...
Paste your code in there...
Tom
 
Upvote 0
OK. I got the code shown above to work consistently.

Now I have a new twist I want to add. I would like to have an input box for the cell number of choice.

I tried using Inputbox function but I come up with a run time error 424.

Here's what I've done.

private sub newsheet()
dim message, title
message = "Enter a cell number for location of page numbers"
title = "Add Page Numbers"
myvalue = inputbox(message, title)
for each sh in worksheets
sh.[myvalue].value = sh.index
next
end sub

Separately I can get both the input box and the pagenumber macro to work but when put together the run time error comes up.

Any ideas?
 
Upvote 0

Forum statistics

Threads
1,213,506
Messages
6,114,025
Members
448,543
Latest member
MartinLarkin

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