+ Reply to Thread
Results 1 to 11 of 11

VBA Comparing Single List to Many Lists & Generating A Text as Result

  1. #1
    Registered User
    Join Date
    10-12-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    17

    VBA Comparing Single List to Many Lists & Generating A Text as Result

    ExcelForumHelp.jpg

    Good day all and happy new year.

    The data I'm dealing with is larger therefore I've simplified it to the above image. I'll do my best to explain what I would like to achieve. I've not started on the VBA codes yet as I don't know where to begin from and my level in VBA is just a beginner.

    As you can see from the image attached, I'd like to have all the information in the whole of column A (taking into account that column A may expand as it depends on the data that is fed in from another sheet - thus the selection of column A has to be able to expand automatically)

    and compare it with information in Column F, Column H and Column J (data in this columns are fixed and need not to be expand), on another note, Column F, H and J are in another worksheet (say "Sheet 2").

    Once the comparison is done, I'd like to have the result shown in Column B indicating "Priority 1" if it is from Column F, "Priority 2" if it is from Column H and "Priority 3" if it is from Column J.

    Apologies if this has been answered in another thread however I tried searching around but I couldn't find the right key words to put together to find the solution that fits.

    Big thanks in advance,
    Aaron

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VBA Comparing Single List to Many Lists & Generating A Text as Result

    Something like this, perhaps:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-12-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: VBA Comparing Single List to Many Lists & Generating A Text as Result

    Thanks for the swift reply ! this works very well !

    However, what if data in column F, H and J are in another sheet like Sheet 2. What modifications to the code that I need to make so that it compares between Column A in sheet 1 and F, H and J in sheet 2 ? I could only understand some of the codes, unsure if what I've just asked has already been written in the code above.

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VBA Comparing Single List to Many Lists & Generating A Text as Result

    This line of the code tells it which sheet to search:

    Please Login or Register  to view this content.
    So if you changed that line to:

    Please Login or Register  to view this content.
    It would search the sheet named "Sheet2".

  5. #5
    Registered User
    Join Date
    10-12-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: VBA Comparing Single List to Many Lists & Generating A Text as Result

    Thanks, where in the code can I change the location of the data in Column A, say I want this code to work if my data was on column C. I have other sheets as well so where can I specify the sheet and the column location in this code.

    Also where in the code covers " I'd like to have all the information in the whole of column A (taking into account that column A may expand as it depends on the data that is fed in from another sheet - thus the selection of column A has to be able to expand automatically) "

    Sorry, if I'm asking a lot of questions. Would like to understand better. Thanks a bunch !
    Last edited by kidengineer; 01-09-2013 at 06:18 AM.

  6. #6
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VBA Comparing Single List to Many Lists & Generating A Text as Result

    I've changed the code to add a new line (in bold) which specifies the source sheet:

    Please Login or Register  to view this content.
    The first proper line of code specifies the column that the data being searched for is in, so:

    Please Login or Register  to view this content.
    1 = Column A, if you wanted your source data to be in column C you'd change that line to:

    Please Login or Register  to view this content.
    The code also automatically finds the last row in the data column containing data and loop down to there, so it will work with any number of entries in the specified data column.

  7. #7
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VBA Comparing Single List to Many Lists & Generating A Text as Result

    Whoops, missed a bit. This line of code:

    Please Login or Register  to view this content.
    Needs to be changed to:

    Please Login or Register  to view this content.
    A small, but important point.

  8. #8
    Registered User
    Join Date
    10-12-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: VBA Comparing Single List to Many Lists & Generating A Text as Result

    Thanks ! I'm trying them out now

  9. #9
    Registered User
    Join Date
    10-12-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: VBA Comparing Single List to Many Lists & Generating A Text as Result

    All works well now ! Mad happy ! Thanks Andrew for your help !

    One more thing though, just came up today, if the data that is on the 'source sheet' could not be found on the 'search sheet' and I want it to show as "No_Priority", what should I add and where to the codes. This would be my last question
    Last edited by kidengineer; 01-10-2013 at 03:04 AM.

  10. #10
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VBA Comparing Single List to Many Lists & Generating A Text as Result

    Really easy. This little bit of code towards the end:

    Please Login or Register  to view this content.
    Just needs to be changed to:

    Please Login or Register  to view this content.
    And that should be it.

  11. #11
    Registered User
    Join Date
    10-12-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: VBA Comparing Single List to Many Lists & Generating A Text as Result

    Thanks ! Everything works great now !

    Thanks so much for your help ! Definitely learnt something new here

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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