+ Reply to Thread
Results 1 to 9 of 9

Alphanumeric Increment based on previous row value

  1. #1
    Registered User
    Join Date
    06-04-2015
    Location
    South East UK
    MS-Off Ver
    2013
    Posts
    28

    Alphanumeric Increment based on previous row value

    Hi all, first post here, please be kind.

    I'm in the process of learning by trying to create a fairly simple solution for my dad, who's far from an IT pro.

    I have a sheet called customers, and on a separate sheet(Homepage) I have some buttons, one of them being 'Add Customer' and I have a vba macro for that, but it's not working 100%.

    The first column contains Customer ID in alphanumeric format, e.g. ABC123 and this is the unique reference for the row. It is only the numeric part of the string that will change, first 3 characters stay the same.

    I'm looking for my code to :

    1- Find next empty row
    2- Find last ID
    3- Create new Customer ID


    I've been reading all sorts of posts and watching tutorials etc, and I think I've just got myself in a muddle now. It has been slightly working but when I tried to tweak it to get it working perfectly, it all went a bit wrong. One of the strange things was that gave me MBL011 when there is already a MBL011 entry....... I have some data in the worksheet to work with, and some of that has been overwritten when I've been testing (god job I have a copy). I'm am quite happy with having to manipulate some data manually, especially to get the data back again (will be copy/paste).

    This is my code that I currently have.....I think the error is on the strNextID, hence why I've been trying different ways.
    Please Login or Register  to view this content.

  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: Alphanumeric Increment based on previous row value

    1) Read the number first by stripping off the MBL from the last code, then add 1, then add the MBL back on.
    2) I would use a "LastRow" (LR) technique that makes it much easier to read/edit the code as to where data is being written on the sheet.

    Like so:
    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
    Registered User
    Join Date
    06-04-2015
    Location
    South East UK
    MS-Off Ver
    2013
    Posts
    28

    Re: Alphanumeric Increment based on previous row value

    Hiya, thanks for the response. I've given that a go but I'm getting a Type Mismatch error on the strNextID........ line. Any ideas?

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

    Re: Alphanumeric Increment based on previous row value

    If you want to post the workbook so I can test it directly, I'll be happy to check it out.

  5. #5
    Registered User
    Join Date
    06-04-2015
    Location
    South East UK
    MS-Off Ver
    2013
    Posts
    28

    Re: Alphanumeric Increment based on previous row value

    Ok, thanks, think I've uploaded it correctly
    Attached Files Attached Files

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

    Re: Alphanumeric Increment based on previous row value

    Ok, my bad, forgot to check for a BLANK database..heh.

    Please Login or Register  to view this content.

    Also, on other tip, in the VBEditor click on the CLOSE FORM button and set the CANCEL=True in the properties. This way pressing ESC when the form is open will also close the form.

  7. #7
    Registered User
    Join Date
    06-04-2015
    Location
    South East UK
    MS-Off Ver
    2013
    Posts
    28

    Re: Alphanumeric Increment based on previous row value

    Lovely, seems to be working like a treat. It does seem to enter the MBL number before the 'New Date Added succesfully' message and entering the inputted data, but I don't think that will be a problem, and I'm sure I could figure out how to sort it.

    Thanks again, I'll marked as solved, add rep, and another other questions I'll post new thread.

    Cheers

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

    Re: Alphanumeric Increment based on previous row value

    SORTing? Beware, nothing we've done takes into account the LAST row not being the highest ID number. If you sort by NAME for instance, and the last row has MBL002 as the ID in column A, the next time you add it will use MBL003. Watch out for sorting!

  9. #9
    Registered User
    Join Date
    06-04-2015
    Location
    South East UK
    MS-Off Ver
    2013
    Posts
    28

    Re: Alphanumeric Increment based on previous row value

    I meant sort in terms of fixing the problem lol, sorry.

    I think the best course of action for me, for this little project, is to make a little bug list. For example, I can't get the next ID to show up on the message box. It's not crucial, but I'd obviously want to fix those little bits at a later date

+ 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: 6
    Last Post: 11-30-2016, 02:38 AM
  2. Increment Alphanumeric Value of a Cell on each print job
    By rudygortiz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-12-2014, 03:55 PM
  3. How to increment column value as per previous column and validations
    By pan07 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-31-2012, 09:57 AM
  4. Replicate and increment alphanumeric keywords?
    By toolsavvy in forum Excel General
    Replies: 7
    Last Post: 12-16-2007, 03:02 AM
  5. Inserting value with increment by 1 from previous value
    By Mikus in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-07-2005, 03: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