+ Reply to Thread
Results 1 to 2 of 2

VBA to compare a date from one sheet to dates on second sheet of multiple similar people?

  1. #1
    Registered User
    Join Date
    07-12-2015
    Location
    London, England
    MS-Off Ver
    2011
    Posts
    8

    VBA to compare a date from one sheet to dates on second sheet of multiple similar people?

    I have to match unique ID's using names from one sheet to the other. The problem is the sheet I'm matching to has some people with the same name so when I get the ID it could not be the right one. That's why I need to compare dates of termination and see if they're similar, so I want to go through and compare the date of termination on the first sheet to the multiple dates of termination on the second sheet and see which one matches up closest and then pull that ID from that person. For example if there were 10 John Smith's on the second file, and I'm trying to match the John Smith on my list to his unique # I'd have to look at his date of termination and see which one of those 10 have the closest date of termination(or if it's the exact same)


    Anyone with the same names have been marked using SUMPRODUCT so next to their name if the next person has the same name there's a number going from 1 - however many multiples there are. Any people with unique names have no number next to their name, the space would be blank. But I'm only working with the multiples since the uniques were easy enough with lookups
    I imagine a macro for this would have to include if num1< num2 (because if two people with duplicate names are next to each other then it would go 1 - 2 (if there are 2 people with the same name) then 1-2-3 (the next has 3 people with the same name) then compare dates and store this then if num2 < num3 then compare dates and store both values and then at the end compare which value has the smallest absolute value then pull the ID for the one with the smallest date which is two columns to the left over.


    It looks something like this

    ID Date of Termination LAST|FIRST Duplicate or not(if blank then unique)
    39432 9/27/1963 JOHNSON|MARK 1
    2929 7/18/1999 JOHNSON|MARK 2
    54392 2/3/2010 JOHNSON|MARK 3
    62345 5/2/1982 JOHNSON|MARK 4
    42902 2/2/2010 SEYMOUR|PHILLIPS
    384298 4/1/2007 MARLEY|BOB 1
    384298 6/24/2004 MARLEY|BOB 2


    and

    ID Date of Termination LAST|FIRST Date difference)
    39432 9/27/2005 MARLEY|BOB Date in this sheet - Date in previous sheet
    54392 4/2/2010 JOHNSON|MARK Date in this sheet - Date in previous sheet
    42902 2/2/2010 SEYMOUR|PHILLIPS Date in this sheet - Date in previous sheet

    All the duplicates in the first sheet are marked in red and have numbers listed next to them listing how many, the unique names have no numbers next to them. The long number all the way to the left is the ID # they should be matched to, almost all these people have the wrong ID matched to them in the second sheet because when I used a lookup it just took the first ID from the many possible ones that could have duplicates.

    I need to make the Column that has "date in this sheet - date inprevious sheet" find the difference of dates that has the smallest absolute value, For example in Mark Johnson's case, the Mark Johnson i'm looking for should have a date of termination near 2010. The only one that matches that is the 3rd Mark Johnson on the main list with ID 54392.

    All the people I'm working with right now have duplicates in the other sheet. None are like Seymour Phillips who match up perfectly because of uniqueness.


    I'm not sure how to exactly write this though, especially on how to use lookups in a macro and have it go to the dates from the numbers then pull the ID which is one column to the left of the dates.

  2. #2
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: VBA to compare a date from one sheet to dates on second sheet of multiple similar peop

    Hi,
    . You have explained quite well what you want, and I think i get the general idea. I do not think a code would be too difficult to do for you..
    . But It would be much easier if you give a clear picture ( Not IMAGES ) of what you have before and after with reduced test data.


    . So simply provide clear before and after ... ( For example a "Before" and "After" sheet in an Excel File )

    To summarise.

    . The Before or Befores, should look just as it / they does before running of any macro.
    .
    . The After or Afters, should be hand filled by you so that it / they looks exactly as you want it to After running of any macro, based on the actual sample data in the Before / or Befores
    . Make sure there is just enough data to demonstrate your need. Remember to desensitize the data if necessary, but use the typical Format type and choose your data carefully so that it can be used to test all possible scenarios.
    ...


    Alan

    P.s.

    To provide that information:..You have provided clear Tables but it would be better to try one of the following, number . 2 ) probably

    ...
    . 1 ) use the Forum Tools in my signature to produce screen shots we can copy to a spreadsheet ( NO IMAGES ! )
    . 2 ) Post Files
    . 2 a) To Attach a sample workbook:
    View Pic
    http://www.excelforum.com/members/da...ch-a-file.html
    http://tinyurl.com/oenwprw
    . 2 b) Send over a file sharing site, such as this free thing
    Box Net,
    https://www.box.com/
    http://tinyurl.com/7chr7u8
    . Remember to select Share and give the link / links they give.
    . 3 c) Only as a last resort, P.M **( Private Message ) . me and i will reply with my Email Addressee so you can send me a file
    ** To PM me, click on my name in the left hand margin when you are logged in, the rest should be obvious.
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

+ 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. VBA to compare a date from one sheet to dates on second sheet of multiple similar people
    By Panglossian in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-11-2015, 01:14 PM
  2. [SOLVED] Need a cell to compare value against another sheet, AND multiple cells on the same sheet
    By Smeghead in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-15-2015, 07:37 AM
  3. Replies: 5
    Last Post: 08-27-2013, 12:46 AM
  4. Reformatting a sheet with many iterations of a similar grouping of dates and values
    By Bobby Green in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-14-2013, 02:19 PM
  5. [SOLVED] Email to multiple people in a sheet
    By shoopes2 in forum Excel General
    Replies: 3
    Last Post: 12-28-2012, 02:10 AM
  6. Replies: 1
    Last Post: 02-22-2010, 05:24 AM
  7. [SOLVED] Compare date against multiple dates
    By Struggling in forum Excel General
    Replies: 1
    Last Post: 04-26-2006, 10:19 AM

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