![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Posts: 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? |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
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
__________________
Kind regards, Al Chara |
|
|
|
|
|
#3 | |
|
New Member
Join Date: Apr 2002
Posts: 6
|
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. Quote:
|
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
I ran Al's bit of code and it worked fine...
Where are you placing your code? Tom |
|
|
|
|
|
#5 | |
|
New Member
Join Date: Apr 2002
Posts: 6
|
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 Quote:
|
|
|
|
|
|
|
#6 |
|
New Member
Join Date: Apr 2002
Posts: 6
|
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 ] |
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
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 |
|
|
|
|
|
#8 |
|
New Member
Join Date: Apr 2002
Posts: 6
|
OK Tom. I'll give that a shot and let you know. Thanks.
Bob |
|
|
|
|
|
#9 |
|
New Member
Join Date: Apr 2002
Posts: 6
|
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? |
|
|
|
|
|
#10 |
|
Board Regular
Join Date: Feb 2002
Location: Las Vegas Nevada USA
Posts: 240
|
Why not use the page numbering function in the Header / Footer utility??
__________________
George Learn to listen. Opportunity sometimes knocks very softly. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|