+ Reply to Thread
Results 1 to 2 of 2

increase number automatically

  1. #1
    starlw116
    Guest

    increase number automatically

    I want to automatically increase the number in a certain cell each time the
    document is saved. I also would like the number in the document name to
    increase each time the document is saved (the new number will be the same for
    both the number in the cell and the document name). The document name is
    currently 0000Estimations (the 0s are where the new number will be).

    Thanks!

  2. #2
    Forum Contributor
    Join Date
    03-23-2006
    Location
    Vancouver
    Posts
    114
    This can be achieved with a simple formula and macro

    Step 1

    Save your file as 0001Estimations.xls

    In Cell A2 enter formula

    =CELL("filename",A1)

    This will return the full path, filename and worksheet name.

    In Cell A3 enter formula

    =FIND("000",A2)

    This will identify the position in the file name and path where your file
    number begins

    In Cell A1, use the value returned in cell A3 in place of nn in the following formula

    =MID(CELL("filename",A2),nn,4)


    You can now clear the contents of Cell A2 and A3.

    Step 2

    Open the Visual Basic Editor
    Right Click on Modules in the top left hand window and Insert > Module

    Copy and Paste the following code:

    Sub SaveAndRename()

    FileNum = ThisWorkbook.Sheets("Sheet1").[A1].Value + 1
    FileNumStr = Format(FileNum, "0000")
    Newfilename = FileNumStr & "Estimations.xls"

    ActiveWorkbook.SaveAs Filename:=Newfilename, _
    FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
    ReadOnlyRecommended:=False, CreateBackup:=False

    Calculate
    End Sub

    You can either create a button to run this macro instead of using File > Save, or attach the macro to the Ctrl-S shortcut.



    Quote Originally Posted by starlw116
    I want to automatically increase the number in a certain cell each time the
    document is saved. I also would like the number in the document name to
    increase each time the document is saved (the new number will be the same for
    both the number in the cell and the document name). The document name is
    currently 0000Estimations (the 0s are where the new number will be).

    Thanks!

+ 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