+ Reply to Thread
Results 1 to 5 of 5

Auto Increment Multiple Sheets

  1. #1
    Registered User
    Join Date
    02-20-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    3

    Auto Increment Multiple Sheets

    Hi All,

    My question is, how can I auto increment numbers across multiple worksheets.

    I have 22 worksheets each sheet has 8 columns, Column A would be the column that when filled (With Text) would generate an auto number in column H2.
    now this needs to happen no matter what sheet I enter data into, the Auto numbers would be added. Preferably I would like a format like: rcp-00001

    I also have a userform that loads when the work book opens, this userform has 22 tabs (multi tab page), each tab has text boxes and a combobox, this are populated from each work sheet.
    so I guess this needs to be taken into consideration for code, as I could end up with ambiguous name. From the userform I can fill the textboxes and save to the corresponding sheet.
    so I already have quite a bit of code going on. All of my worksheets have there own name, although I don't think this matters as they can still be refered to as Sheet1, Sheet2 etc etc.

    so in a nut shell if I enter data into sheet1 starting at A2 across to F2 this would auto generate a number in H2 ie (rcp-00001)
    then if I entered data into sheet 12 at A2 to F2 it would generate a number in H2 ie (rcp-00002)

    I hope my explanation is understandable.
    thanks for any advice or help in advance.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Auto Increment Multiple Sheets

    Add this code to the Thisworkbook tab in the VBA editor.

    Please Login or Register  to view this content.
    remember to save as .xlsm

  3. #3
    Registered User
    Join Date
    02-20-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    3

    Re: Auto Increment Multiple Sheets

    Thanks I will try this and let you know the outcome

  4. #4
    Registered User
    Join Date
    02-20-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    3

    Re: Auto Increment Multiple Sheets

    Ok I put this code into a blank workbook and it operates perfectly.
    I added the code to my workbook and I get nothing. not quite sure way below is my code for thisworkbook.

    with your code added see bottom I have a workbook open event would this conflict?

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Dim MaxNumber As Long
    Dim Sheet As Worksheet
    If Target.Column = 1 Then
    For Each Sheet In ThisWorkbook.Sheets
    For N = 1 To Sheet.Cells(Rows.Count, 8).End(xlUp).Row
    If Left(Sheet.Cells(N, 8), 4) = "rcp-" Then
    If Int(Right(Sheet.Cells(N, 8), 5)) > MaxNumber Then
    MaxNumber = Int(Right(Sheet.Cells(N, 8), 5))
    End If
    End If
    Next N
    Next Sheet
    End If
    Application.EnableEvents = False
    MaxNumber = MaxNumber + 1
    Target.Offset(0, 7) = "rcp-" & Left("000000", 6 - Len(Str(MaxNumber))) & MaxNumber
    Application.EnableEvents = True
    End Sub



    Option Explicit

    Private Sub Workbook_Open()
    Commandfrm.Show
    End Sub

  5. #5
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Auto Increment Multiple Sheets

    Try with Option Explicit at the top

    and use this version where N is declared.

    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)

Similar Threads

  1. Replies: 2
    Last Post: 07-29-2015, 10:07 AM
  2. Auto increment a value across multiple worksheets
    By Ted Dennis in forum Excel General
    Replies: 1
    Last Post: 04-20-2015, 05:20 AM
  3. Replies: 26
    Last Post: 02-18-2013, 05:46 PM
  4. [SOLVED] Auto increment next cell when adding multiple entries from userform
    By chriscoetser in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-02-2013, 02:15 AM
  5. Auto increment over multiple worksheets
    By Ethan in forum Excel Formulas & Functions
    Replies: 24
    Last Post: 09-06-2005, 12:05 PM

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