Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Page numbers in a cell

  1. #1
    New Member
    Join Date
    Apr 2002
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #2
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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
    Best regards,
    Allan Chara
    http://www.mrspreadsheets.com

  3. #3
    New Member
    Join Date
    Apr 2002
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  4. #4
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I ran Al's bit of code and it worked fine...
    Where are you placing your code?
    Tom

  5. #5
    New Member
    Join Date
    Apr 2002
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  6. #6
    New Member
    Join Date
    Apr 2002
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #7
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #8
    New Member
    Join Date
    Apr 2002
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    OK Tom. I'll give that a shot and let you know. Thanks.
    Bob

  9. #9
    New Member
    Join Date
    Apr 2002
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #10
    Board Regular
    Join Date
    Feb 2002
    Location
    Las Vegas Nevada USA
    Posts
    239
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Why not use the page numbering function in the Header / Footer utility??
    George

    Learn to listen. Opportunity sometimes knocks very softly.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •