Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jul 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Excel 2013 Help Needed

    I'm trying to work on some database stuff in Excel for my company, and one thing I would like to do is setup an autogenerating number field.

    As an example:

    I open up the spreadsheet file, and I have a button to "refresh 'X' number" and it will provide me with the next sequential number based on the previous generated one.

    File 1 was GB-001-14

    Next time I open the file and hit refresh, it generates GB-002-14, and so on...

    Is this possible, if so HOW???

    Thanks in advance.

    Geoffrey (new here)

  2. #2
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,468
    Thanks
    30
    Thanked 61 Times in 57 Posts
    Welcome.

    I'm not a strong VB person, but I recorded this macro with your original "value" in H2.

    Sub Increment()
    '
    ' Increment Macro
    '
    Range("H4").Select
    ActiveCell.FormulaR1C1 = _
    "=LEFT(R[-2]C,3)&(TEXT(1+MID(R[-2]C,4,3),""000"")&RIGHT(R[-2]C,3))"
    Range("H4").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("H2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Range("H4").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    End Sub
    Last edited by kweaver; 2014-07-14 at 19:31.

  3. #3
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,631
    Thanks
    115
    Thanked 645 Times in 589 Posts
    Gvandale,

    Another approach is placing this code in the Workbook_open event routine of ThisWorkbook module where A1 is the cell with the incrementing value:

    Code:
    Private Sub Workbook_Open()
    With Worksheets("Sheet1") 'CHANGE SHEET1 TO NAME OF THE SHEET
        s = Split(.Range("A1"), "-") 'CHANGE A1 TO CELL THAT HAS VALUE
        s(1) = s(1) + 1
        s(1) = Format(s(1), "00#")
        .Range("A1") = s(0) & "-" & s(1) & "-" & s(2)
    End With
    End Sub
    The value will automatically increment when the workbook opens

    HTH,
    Maud
    Attached Files Attached Files
    Last edited by Maudibe; 2014-07-15 at 07:16.

Posting Permissions

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