+ Reply to Thread
Results 1 to 10 of 10

Automatically assign a code number to a list of products?

  1. #1
    Registered User
    Join Date
    06-03-2014
    Location
    Brazil
    MS-Off Ver
    Office 365
    Posts
    52

    Automatically assign a code number to a list of products?

    There's a table with products, and I would like that whenever I add a new product to it, Excel automatically adds an unique code number to column A, based on the highest value found on that table column+1

    Its not in sequence since I re order the products constantly

    And it can't be based on the row number since I remove products too, and I don't want an already asigned code to change

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Automatically assign a code number to a list of products?

    Okay, you cannot do this with formulas since the formula will recalculate once you remove that number. It will need to be done with VBA. Can you upload an example of how it will be (a spreadsheet) so that I have something to work with? Go Advanced>Manage Attachments
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    06-03-2014
    Location
    Brazil
    MS-Off Ver
    Office 365
    Posts
    52

    Re: Automatically assign a code number to a list of products?

    Quote Originally Posted by ChemistB View Post
    Okay, you cannot do this with formulas since the formula will recalculate once you remove that number. It will need to be done with VBA. Can you upload an example of how it will be (a spreadsheet) so that I have something to work with? Go Advanced>Manage Attachments
    Ah ok, if VBA is the only way then I can do it, just loop through A and find highest number

    I was just wondering, a button would be really unpleasant, can the module be added to an automatic event on the table or something like that?

  4. #4
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365 Version 2501 64-bit
    Posts
    1,465

    Re: Automatically assign a code number to a list of products?

    ppgab,

    Yes, the attached Macro runs automatically every time you add something to Col B.

    Please Login or Register  to view this content.
    Add it to worksheet, NOT a module.

    Hope it helps
    Last edited by Ochimus; 03-07-2016 at 12:19 PM.

  5. #5
    Registered User
    Join Date
    06-03-2014
    Location
    Brazil
    MS-Off Ver
    Office 365
    Posts
    52

    Re: Automatically assign a code number to a list of products?

    @Ochimus Thanks for your time friend, I added it but it only adds the code 109 for some reason, I've added the workbook as attachment, is the "produtos" sheet
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Automatically assign a code number to a list of products?

    Near the end of Ochimus' code is

    Please Login or Register  to view this content.
    Modify that depending on what sheet you are in.
    Ochimus's code does not "remember" numbers that you've erased however. I would suggest that you assign a cell to track that, maybe somewhere off to the right, i.e. cell W1. then change this line
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Does that help?

  7. #7
    Registered User
    Join Date
    06-03-2014
    Location
    Brazil
    MS-Off Ver
    Office 365
    Posts
    52

    Re: Automatically assign a code number to a list of products?

    @ChemistB Its the same sheet, so couldn't it be just

    Please Login or Register  to view this content.
    ?

    Or better yet, I was thinking, the table is called "Table44" , is there a function or global var that returns the number of rows a table has? So it would be more efficient than Range("A1:A1000")

    Thanks for all the help, I'm learning a lot

  8. #8
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365 Version 2501 64-bit
    Posts
    1,465

    Re: Automatically assign a code number to a list of products?

    ppgab,

    I have no idea why the macro keeps creating "109" on your file.

    As you can see on the attached, I copied your "produtos" sheet, and used the same Macro,

    If you add new product to the attached. everything works perfectly!

    Ochimus
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    06-03-2014
    Location
    Brazil
    MS-Off Ver
    Office 365
    Posts
    52

    Re: Automatically assign a code number to a list of products?

    @Ochimus it's because the rng was taking range from sheet1, my list is actually on sheet2 but it's working just fine now, thanks pal

  10. #10
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365 Version 2501 64-bit
    Posts
    1,465

    Re: Automatically assign a code number to a list of products?

    ppgab,

    Glad it's sorted out, Teach me a lesson about using the "active sheet" instead of the sheet number in future!

    Thinking about your question over the "set" range limit, the simple answer is to set a "dynamic" range for the "Descrição".

    If you are not familiar with it,

    Click the Formulas tab.
    In the "Defined Names" group, click Name Manager.
    Click New.
    In the Name box, type Descrição.
    In the Refers to box, type the following text, and then click OK:
    =OFFSET($B$2,0,0,COUNTA($B$:$B),1)
    (Being dynamic, it will resize automatically as you add more names).

    Then replace the row numbers in the Macro with the Range Name.

    Ochimus

+ 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. Sub to assign products to machines
    By Jalokin in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-16-2016, 06:33 AM
  2. [SOLVED] Item Database: Automatically assign number to items(store products)
    By AEvans190 in forum Excel General
    Replies: 18
    Last Post: 10-22-2013, 04:27 PM
  3. Find and go to product code in a list of products
    By ALANBERNARD in forum Excel General
    Replies: 5
    Last Post: 06-05-2013, 09:28 AM
  4. How to automatically assign next available number
    By Apri11 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2012, 08:06 AM
  5. How do I assign dollar value to particular products.
    By nataniele in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 04-19-2010, 05:24 AM
  6. Replies: 1
    Last Post: 01-11-2006, 02:45 PM
  7. [SOLVED] How do I automatically assign an invoice number in Excel 2003 (I .
    By CliveA in forum Excel General
    Replies: 0
    Last Post: 04-15-2005, 07:06 AM

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