Page 1 of 2 12 LastLast
Results 1 to 10 of 11

How to Put a counter in Excel ?

This is a discussion on How to Put a counter in Excel ? within the Excel Questions forums, part of the Question Forums category; I would like to put a counter (number) in my excel sheet. Consider that like a bill number. Any time ...

  1. #1
    New Member
    Join Date
    Apr 2009
    Posts
    22

    Default How to Put a counter in Excel ?

    I would like to put a counter (number) in my excel sheet. Consider that like a bill number. Any time I open my Excel I want to have new number on top. For example 201, 202 so on and so forth. I would appreciate if anyone had this project before and willing share it with me.

    Many Thanks

    A Maftoun

  2. #2
    VoG
    VoG is offline
    MrExcel MVP
    Moderator
    VoG's Avatar
    Join Date
    Jun 2002
    Location
    127.0.0.1
    Posts
    63,136

    Default Re: How to Put a counter in Excel ?

    Hello and welcome to MrExcel.

    Try this: right click the Excel logo just to the left of File on the menu bar, select View Code and paste in

    Code:
    Private Sub Workbook_Open()
    With Sheets("Sheet1").Range("A1")
        .Value = .Value + 1
    End With
    End Sub
    Change Sheet1 and A1 to suit.
    HTH, Peter
    Please test any code on a copy of your workbook.

  3. #3
    Board Regular
    Join Date
    Jul 2008
    Location
    Cleveland, OH
    Posts
    636

    Default Re: How to Put a counter in Excel ?

    You want the number in the same cell, and to increment every time the file is opened? Maybe something like

    Code:
    Private Sub Workbook_Open()
    With Sheets("Sheet1").Range("A1")
        If Not IsNumeric(.Value) Then .Value = 1
        .Value = .Value + 1
    End With
    End Sub
    But there might be a better solution if you can explain what the purpose of this is.
    Last edited by gauntletxg; Apr 28th, 2009 at 01:12 PM.

  4. #4
    New Member
    Join Date
    Apr 2009
    Posts
    22

    Default Re: How to Put a counter in Excel ?

    Thanks all

    You mean I have to run it as Macro?

  5. #5
    VoG
    VoG is offline
    MrExcel MVP
    Moderator
    VoG's Avatar
    Join Date
    Jun 2002
    Location
    127.0.0.1
    Posts
    63,136

    Default Re: How to Put a counter in Excel ?

    Either of those macros will run automatically every time you open the workbook.
    HTH, Peter
    Please test any code on a copy of your workbook.

  6. #6
    New Member
    Join Date
    Apr 2009
    Posts
    22

    Default Re: How to Put a counter in Excel ?

    How I can enable Macro on 2007 excel? doesnot let me save it.

  7. #7
    VoG
    VoG is offline
    MrExcel MVP
    Moderator
    VoG's Avatar
    Join Date
    Jun 2002
    Location
    127.0.0.1
    Posts
    63,136

    Default Re: How to Put a counter in Excel ?

    Click the Office button then Save As and save as Excel Macro-enabled Workbook.

    Then click the Office button again, click Excel Options and tick Show Developer tab in the Ribbon then click OK.

    On the Developer tab click Macro Security and set it to Enable all macros.

    Press ALT + F11 to open the Visual Basic Editor. In the Project - VBA Project window double click ThisWorkbook and paste in the code.

    Save, close then re-open your workbook to see the effect.
    HTH, Peter
    Please test any code on a copy of your workbook.

  8. #8
    New Member
    Join Date
    Apr 2009
    Posts
    22

    Default Re: How to Put a counter in Excel ?

    I can not to pass this step "Then click the Office button again, click Excel Options and tick Show Developer tab in the Ribbon then click OK."
    Am I missing somthing? I can not find Options to continue.

    Thanks for your help

    Abdi Maftoun

  9. #9
    VoG
    VoG is offline
    MrExcel MVP
    Moderator
    VoG's Avatar
    Join Date
    Jun 2002
    Location
    127.0.0.1
    Posts
    63,136

    Default Re: How to Put a counter in Excel ?

    HTH, Peter
    Please test any code on a copy of your workbook.

  10. #10
    New Member
    Join Date
    Apr 2009
    Posts
    22

    Default Re: How to Put a counter in Excel ?

    Thanks all

    I am still working on this simple code. The first code does not work. when Debug it give this massege

    Application.Run "Book1!Macro1".

    the sesond code works but I have run it every time. there is away when i open my Excel templet just one number to the last one

    thanks for your help

    Abdi Maftoun

Page 1 of 2 12 LastLast

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
  •  


DMCA.com