+ Reply to Thread
Results 1 to 17 of 17

Generate Auto Number Using VBA

  1. #1
    Registered User
    Join Date
    03-13-2016
    Location
    Yemen
    MS-Off Ver
    2016
    Posts
    59

    Generate Auto Number Using VBA

    Hello All

    I have in my sheet the below formula:
    =IF(ISBLANK(H12),"",A11+1)
    To generate an automatic sequence number, depend on the cell in H column if it is not blank
    I have a problem in above formula; when delete one row the sequence number following that deleted row gives errors

    Whatever

    I think to change it to VBA
    May I have vba code doing the same job? But without any problem when deleting any row and keep the others row numbers the same without change.
    I hope it is clear

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Generate Auto Number Using VBA

    Hello stoicy,

    Your issue depends on how you have your Workbook set-up, and if any VBA Code is at play.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window (or use the paperclip icon).

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Registered User
    Join Date
    03-13-2016
    Location
    Yemen
    MS-Off Ver
    2016
    Posts
    59

    Re: Generate Auto Number Using VBA

    see attached
    Attached Files Attached Files

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Generate Auto Number Using VBA

    Hi there,

    A defined name formula (native Excel, not VBA) might be the way to achieve this. In which cell are you inserting the formula:

    Please Login or Register  to view this content.

    Even better, can you post a sample of your worksheet here so we can see where the various values are coming from?


    Regards,

    Greg M

  5. #5
    Registered User
    Join Date
    03-13-2016
    Location
    Yemen
    MS-Off Ver
    2016
    Posts
    59

    Re: Generate Auto Number Using VBA

    Quote Originally Posted by Greg M View Post
    Hi there,

    A defined name formula (native Excel, not VBA) might be the way to achieve this. In which cell are you inserting the formula:

    Please Login or Register  to view this content.

    Even better, can you post a sample of your worksheet here so we can see where the various values are coming from?


    Regards,

    Greg M
    same problem

    if possible to be by VBA

    Thanks

  6. #6
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Generate Auto Number Using VBA

    Hi again,

    Thanks for posting your workbook - I hadn't seen your reply when I sent my message

    Take a look at the attached workbook and see if it does what you need. It contains a defined name formula "forAutoSum" which is used to autonumber the cells in Column A.

    The defined name function will continue to operate correctly even when rows are deleted. (Mind you, deleting a row seems to generate error conditions within your existing VBA code!)


    Anyway, hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    03-13-2016
    Location
    Yemen
    MS-Off Ver
    2016
    Posts
    59

    Re: Generate Auto Number Using VBA

    Thank you Greg M for your reply, you are so polite

    Auto number is working but when deleting any row it gives the same number to the next row


    I want every row to keep its number, I mean when any row get its generated number; it must be kept the same.


    I prefer to have vba because there are many users for this sheet and it may somebody delete the formula so I prefer to be by vba

    Please Login or Register  to view this content.
    it will be great if anybody help me modify the above code to be used in my sheet

    thank you

  8. #8
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Generate Auto Number Using VBA

    Hi again,

    Many thanks for your very prompt feedback.

    Sorry, I didn't realise that an autonumber should remain constant once it has been assigned.

    The attached version of your workbook uses a hidden helper Column A which allows rows to be deleted while maintaining the original values of the autonumbers.

    By the way, I tweaked your VBA code so that deleting a row no longer causes it to crash.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    03-13-2016
    Location
    Yemen
    MS-Off Ver
    2016
    Posts
    59

    Re: Generate Auto Number Using VBA

    it is clever idea to generate auto number, but in my sheet adding column or hide one is affected other vba codes in my sheet and that is what happened with me.


    I wish to have VBA code so it is not affect anything in my sheet or obliged me to use, add, other cells.


    Thank you my friend

  10. #10
    Registered User
    Join Date
    03-13-2016
    Location
    Yemen
    MS-Off Ver
    2016
    Posts
    59

    Re: Generate Auto Number Using VBA

    Good Morning All

    Any expert here can find VBA code?

  11. #11
    Registered User
    Join Date
    03-13-2016
    Location
    Yemen
    MS-Off Ver
    2016
    Posts
    59

    Re: Generate Auto Number Using VBA

    any body can help please

  12. #12
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Generate Auto Number Using VBA

    Hi again,

    Clear all of the formulas in Column A and then modify the start of your code as per the highlighted rows:

    Please Login or Register  to view this content.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  13. #13
    Registered User
    Join Date
    03-13-2016
    Location
    Yemen
    MS-Off Ver
    2016
    Posts
    59

    Re: Generate Auto Number Using VBA

    Greg M

    Are you magician

    kidding

    it is perfect, I put this question in many excel forum but no one give me what I need exactly

    I really appreciate your help and support

    you keep patient form the beginning even my question and language is not clear

    thank you again and I wish you all the best

  14. #14
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Generate Auto Number Using VBA

    Glad to see you may have your answer, but this post goes against our forum rules about cross posting.

    This thread cannot continue until Rule #8 has been complied with...

    8. Don't cross-post without a link. Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post. Expect cross-posts without a link to be closed.
    HTH
    Regards, Jeff

  15. #15
    Registered User
    Join Date
    03-13-2016
    Location
    Yemen
    MS-Off Ver
    2016
    Posts
    59

    Re: Generate Auto Number Using VBA

    I am sorry I did not understand what is the cross-post mean

    but now it is clear for me


    sorry

  16. #16
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Generate Auto Number Using VBA

    No problem. Just take a read of the forum rules and I'm sure it won't happen again.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  17. #17
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Generate Auto Number Using VBA

    Hi again,

    Moderators: I hope I'm allowed to reply here now that the cross-posting issue has been cleared up.

    Stoicy: Many thanks for your feedback and also for the reputation increase - much appreciated

    You're very welcome - I'm glad I was (finally!) able to help.

    Best regards,

    Greg M

+ 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. [SOLVED] Auto generate a number in a textbox
    By Adnamut in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-23-2014, 04:48 AM
  2. [SOLVED] VBA Auto Generate Next Number
    By sagar007 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-22-2013, 12:05 PM
  3. Excel 2007 : Auto Generate Next Number
    By wisedave in forum Excel General
    Replies: 6
    Last Post: 05-11-2011, 10:36 AM
  4. Auto Generate NUmber
    By Mooseman60 in forum Excel General
    Replies: 1
    Last Post: 10-03-2010, 10:52 AM
  5. auto generate number
    By kryt0n in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-23-2010, 07:52 AM
  6. number to auto-generate
    By dsammons3 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-28-2007, 03:48 PM
  7. Auto generate number???
    By iluminatae in forum Excel General
    Replies: 9
    Last Post: 02-11-2007, 07:43 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