+ Reply to Thread
Results 1 to 3 of 3

Help with turning off auto numbering once a excel file is saved

  1. #1
    Registered User
    Join Date
    09-06-2011
    Location
    Crystal Lake, IL USA
    MS-Off Ver
    Excel 2003
    Posts
    1

    Help with turning off auto numbering once a excel file is saved

    My company is now using Microsoft 2010. First let me say I have no experience in writing macros or VBA Project. I copied a code from a forum that worked to provide auto numbering to our Excel Travel & Expense form. I would like to save the Excel template/or spreadsheet on our common drive forcing users to open (to get the auto number) and save a copy each time to their H:\drive. Once the file is saved on the H:\ drive the auto number needs to be turned off. This would allow the user to continue editing the document if necessary and to avoid duplicate numbering. Can anyone help me write a code? Below is what I have to turn the auto numbering on. I also need to protect certian fields in the document from being type in.

    Private Sub Workbook_Open()
    With Range("J5")
    .NumberFormat = "0000000"
    .Value = .Value + 1
    End With
    End Sub

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help with turning off auto numbering once a excel file is saved

    This is the technique I use. It presumes you are opening the template via shortcuts so that it never really opens the template, but a new workbook, each time. The workbook_open does the same thing yours does, with the exception you forgot to include the Sheet Name reference in yours. Best include that...

    Also, I've designated cell AA1 as the "doublecheck" cell on my new workbook, and it will only increment the number if that cell is empty. The workbook_beforesave event not only increments the actual template, but it puts a flag in AA1 to make sure this workbook never does any of this activity again.

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help with turning off auto numbering once a excel file is saved

    With multiple people accessing the same template, I realized you really might need to make the "numbering" part occur compltely during the SaveAs part. So here's the function without the Workbook_Open macro at all. When you do a SaveAs, it will secretly reopen the template, increment the CURRENT number by one, remember it, save the template, put that number into your current workbook, then continue with a normal SaveAs function.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1