+ Reply to Thread
Results 1 to 12 of 12

adding a name to a list if it does not already exist

  1. #1
    Registered User
    Join Date
    08-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    40

    adding a name to a list if it does not already exist

    Hello,

    I am looking at a column of names (the source), and if one of the names from source is not in a different list (master) I want to add it to that list (master).

    My logic seems to make sense, but I think I am getting stuck on the loops. In my outer loop (j), I am temporarily storing each name as a dummy variable (source_name). I am then looping through each of the names in the other list (the x loop). If they match, then end this "for" loop and go on to the next name in the source. If they do not match, check the next name in the master. When it has checked all of the master names against the source name and there is still no match, it will enter the source name in the first empty row in the first column.

    Is it possible that my "End for" is ending my outside loop instead of my inside loop? It keeps telling me that I have a next without a for, so I think that may be my problem.

    Is there a way to let the program know which for loop I would like it to end?

    Please Login or Register  to view this content.
    Maybe I am just looking at this incorrectly, but it seems like it should work.

    Any suggestions?

    Also, can you exit an internal for loop and go to the next iteration of the outside loop? That is essentially what I am doing.

    Thanks,
    Shannon
    Last edited by slaneues; 09-24-2012 at 02:36 PM.

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: adding a name to a list if it does not already exist

    can you upload a workbook with the layout of your workbook and show where you want the results to be placed?
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Registered User
    Join Date
    08-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    40

    Re: adding a name to a list if it does not already exist

    Here is the short version

    Source:
    Frank
    Bob
    Joe
    Sally

    Master:
    Frank
    Sally

    After I run the macro, I would like Master to Read
    Frank
    Sally
    Bob
    Joe

    There are a lot of other things going on in this macro, so I am just trying to do this one step at a time. A simple copy/paste wont work because there is data in the columns of Master that correspond to Each of the names. I am just trying to get anny new name that appears in Source to appear in master in the same column that the rest of the names are in.

    Any suggestions would be greatly appreciated.

    Thanks!

    Shannon

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: adding a name to a list if it does not already exist

    See if you can adjust this to your needs

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    40

    Re: adding a name to a list if it does not already exist

    I am not quite following what this code is doing, but I will give it a shot.

    How do I name the worksheets if they are in different workbooks? The "master" sheet will be in the workbook where the macro is stored and the "source" will be in a different workbook.

    Thanks,
    Shannon

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: adding a name to a list if it does not already exist

    It would of been nice to know that the source names are coming from another workbook! Are both workbooks open when your running this Macro? If so try this. Change Book1.xlsx for you needs.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    40

    Re: adding a name to a list if it does not already exist

    My appologies for forgetting to mention that.

    What you just gave me worked like a charm. Thank you!!!

    I then tried to alter is slightly to reference a closed workbook. I did this simply by opening the other workbook using VBA, but then I ended up getting an error: Runtime error, subscript out of range.

    Do I somehow have to activate or select the workbook that I am running the macro from?

    Thanks again!!

    Shannon

  8. #8
    Registered User
    Join Date
    08-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    40

    Re: adding a name to a list if it does not already exist

    I played around with it a bit and got it to work.

    MANY MANY THANKS!!

    Shannon

  9. #9
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: adding a name to a list if it does not already exist

    Ok glad you got it working.

  10. #10
    Registered User
    Join Date
    08-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    40

    Re: adding a name to a list if it does not already exist

    Mike,

    It seems to work fine, but tomorrow at work I will have to mess around with it. There is something that I forgot about the source sheet that may prove problematic for the code.

    Thanks again!

    Shannon

  11. #11
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520
    Ok Shannon, no problem.

  12. #12
    Registered User
    Join Date
    08-15-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    40

    Re: adding a name to a list if it does not already exist

    I tried it and it works!!

    I ran into a problem with another part of my program, but I will start a new thread for that one.

    Thanks again!

    Shannon

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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