+ Reply to Thread
Results 1 to 16 of 16

Find if a given value is in a cell, if so then try next value until unique

  1. #1
    Registered User
    Join Date
    05-09-2012
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    21

    Angry Find if a given value is in a cell, if so then try next value until unique

    I have the below sub that checks on a separate worksheet if the created number in textbox8 already exists, at the moment there is a message box that alerts the user that the part number already exists, they have to click OK, then the number is incremented by 1, the process is repeated until a unique number is found. This is the written to the worksheet along with some other data.

    What I need to do is remove the message box so it will automatically search and find the next available number.

    I added the following code to the sub, but this has no effect:

    Please Login or Register  to view this content.
    Code for sub

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    11-12-2014
    Location
    Nottingham
    MS-Off Ver
    2013
    Posts
    383

    Re: Find if a given value is in a cell, if so then try next value until unique

    What about:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-09-2012
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    21

    Re: Find if a given value is in a cell, if so then try next value until unique

    Unfortunatley this give a compile error: Next without For.
    If I correct this to the following

    Please Login or Register  to view this content.
    I now get a run-time error '9': subscript out of range

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Find if a given value is in a cell, if so then try next value until unique

    Review your code and you'll know why you're getting a subscript out of range.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-09-2012
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    21

    Re: Find if a given value is in a cell, if so then try next value until unique

    Sorry but i'm not sure what you mean?
    Quote Originally Posted by JOHN H. DAVIS View Post
    Review your code and you'll know why you're getting a subscript out of range.

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Find if a given value is in a cell, if so then try next value until unique

    Check the spelling of your sheet names. They don't match. Shouldn't they?

  7. #7
    Registered User
    Join Date
    05-09-2012
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    21

    Re: Find if a given value is in a cell, if so then try next value until unique

    You are right, my eyesight must be failing me!!

    After the correction, it works without an error, but will not increment by 1 on the textbox26 value, it just creates the same number and inserts this onto the next row.
    Last edited by bigfoot007; 04-01-2015 at 08:01 AM. Reason: spelling

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Find if a given value is in a cell, if so then try next value until unique

    Not sure about what you are trying too do, but that specific piece of code seems to me is only selecting the cell, then continuing with the Loop. I don't where it takes any action. Is it supposed too?

  9. #9
    Valued Forum Contributor
    Join Date
    11-12-2014
    Location
    Nottingham
    MS-Off Ver
    2013
    Posts
    383

    Re: Find if a given value is in a cell, if so then try next value until unique

    my bad on the spelling! Try...
    Please Login or Register  to view this content.
    I'm a bit of an amateur so there may be slight mistakes in the coding as we don't have a template to work with!

  10. #10
    Registered User
    Join Date
    05-09-2012
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    21

    Re: Find if a given value is in a cell, if so then try next value until unique

    I have attached the worksheet, it is simple to use, just click on the big gery button, user form will appear, just need to select from department dropdown "Parts" , then from the type dropdown "Machined Parts",click the radio button, then click creatye final article number.
    it will come up with 501-0001, but this is incorrect as it already exists in the existing worksheet, what it should do is go to 501-0002
    Article Number Request v5aset.xlsm

  11. #11
    Valued Forum Contributor
    Join Date
    11-12-2014
    Location
    Nottingham
    MS-Off Ver
    2013
    Posts
    383

    Re: Find if a given value is in a cell, if so then try next value until unique

    Did you try that code to see if it did what you wanted?

  12. #12
    Registered User
    Join Date
    05-09-2012
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    21

    Re: Find if a given value is in a cell, if so then try next value until unique

    I have tried the code but this still does the same, overwrites the first number and doesnt increase

  13. #13
    Valued Forum Contributor
    Join Date
    11-12-2014
    Location
    Nottingham
    MS-Off Ver
    2013
    Posts
    383

    Re: Find if a given value is in a cell, if so then try next value until unique

    Slight adjustment...
    Please Login or Register  to view this content.
    Last edited by ARowbot; 04-01-2015 at 11:39 AM.

  14. #14
    Registered User
    Join Date
    05-09-2012
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    21

    Re: Find if a given value is in a cell, if so then try next value until unique

    sorry still not working, no errors, but now it just appends the same number to the end of the list on the sheet "existing".
    I thought this would be easy!!

  15. #15
    Valued Forum Contributor
    Join Date
    11-12-2014
    Location
    Nottingham
    MS-Off Ver
    2013
    Posts
    383

    Re: Find if a given value is in a cell, if so then try next value until unique

    I believe I have spotted the problem...
    Textbox 26 is "-0001" By default.
    I now have a code to increase this by 1...However that will go to 0 Rather than your requested "-0002"
    You need to change your idea slightly!
    Here is the latest code to increase it by one once you have done that!

    Please Login or Register  to view this content.
    EDIT: I have now corrected your Code for you...Only problem is it no longer leaves it in the correct format of "0000" for you. I'm unsure on that bit of coding so you will have to correct that bit

    Please Login or Register  to view this content.
    Last edited by ARowbot; 04-01-2015 at 12:35 PM.

  16. #16
    Registered User
    Join Date
    05-09-2012
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    21

    Re: Find if a given value is in a cell, if so then try next value until unique

    Brilliant, that has done the trick, thanks for all the help.

+ 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] Detect unique values in cell and find them in column to count them
    By Ivancitomusic in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-02-2015, 02:37 PM
  2. How to find unique identifier and add data to cell
    By browndog in forum Excel General
    Replies: 1
    Last Post: 10-19-2014, 09:23 PM
  3. Find a unique number in a cell and pull the data into a new cell
    By dazydktp in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-30-2013, 03:02 PM
  4. How to find the unique value and display it in relevant cell
    By danfullwood in forum Excel General
    Replies: 6
    Last Post: 02-05-2013, 08:30 AM
  5. Find Unique cell then copy to other sheets
    By ny_chris in forum Excel General
    Replies: 5
    Last Post: 08-18-2009, 09:39 PM

Tags for this Thread

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