• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Comparing Multiple Tables

matilda

New Member
Guys I'm thoroughly stuck. This might get complicated, so bear with me.

I have 3 tables, we'll call them A, B, C, each on a different sheet within the same workbook. They're basically staff expenditure logs (the information below is a brief example).

Table A looks like this (the columns start at A (Staff Name):
Code:
      A              B             C             D             E               F
1 Staff Name     Start Date     End Date     01/01/2014     02/01/2014     03/01/2014
2 Bob Smith      13/07/2001     20/11/2014        
3 John Abbott    02/09/2002     15/06/2003        
etc
The dates across the top contain every day of the year.

Table B looks like this:
Code:
Staff Name     Fin Start Date     Fin End Date     Amount
Bob Smith      01/11/2001         30/12/2001         £35
John Abbott    01/01/2014         04/04/2014         £44

Table C looks like this:
Code:
Staff Name     Date          Spend
John Abbott    03/10/2002     £55
Bob Smith      02/01/2014     £66.50

What I need to do is compare the tables and pull information from tables B and C into table A. I need 2 checks doing:

If the staff name in Column A (Table A) matches an entry in the Staff name column in Table B and the date in Table A, Row 1 falls between the Fin Start Date and Fin End Date on Table B, then pull that financial figure through to table A.

Otherwise, if the Staff Name (column A) and Date (Row1) from Table A match the staff name and date columns in table C then the Spend figure should be pulled through to table A.

With the information above, the result would look something like this:
Code:
      A              B             C             D             E               F
1 Staff Name     Start Date     End Date     01/01/2014     02/01/2014     03/01/2014
2 Bob Smith      13/07/2001     20/11/2014                       £66.50
3 John Abbott    02/09/2002     15/06/2003       £44          £44            £44
etc

Because each of the dates on table A fall between the dates on Table B for John Abbott and Bob Smith has one matching entry on Table C.

I have to do this for about 3000 entries on each sheet. I had originally set up formulas for this, but they just gummed up the system and crashed it every time, for obvious reasons.

There must be a better way to do it, but I am crap with VBA.

Any help would be appreciated.
 
Thanks Narayan.

I've added some sample data in. I'm just thoroughly stuck.
 

Attachments

  • example.xlsx
    13.7 KB · Views: 3
Damn. Yeah, sorry.

When running the second check (comparing the date in Table C), the date on Table A (Row 1) must match the date on Table C and must also fall between the dates in table A (columns B & C)

I forgot that as part of my initial explanation.
 
Hi Matilda ,

Still somewhat confusing ; Bob Smith has 2 entries in Table B ; in one of them the amount is 62.50 , while in the other 53 ; in such a case , what is to be done ?

Narayan
 
Narayan

That's my fault. I'm rushing to get this done and am making mistakes. This version is better. I have removed the duplicates from sheet B.

Thanks
 

Attachments

  • example.xlsx
    13.6 KB · Views: 2
Hi Matilda ,

There were two more duplicates on the tab C ; I removed them , and copied the old data to the tab OLD C.

See if this is what you were looking for.

Narayan
 

Attachments

  • Example.xlsx
    138.1 KB · Views: 6
Back
Top