Find match of two variables and compare a third

  • Greetings to all.


    I have not done any vba editing in a few years and would like some assistance if possible.


    I have attached an example workbook.


    I would prefer a vba solution but am open to any other options.


    The premise is employees have a gas card. i would like to compare the use of each card to the time card report. In short, was the card used while the employee was on the clock or not.


    The attached workbook has two sheets "CC Data" has the card usage and "Time2" has the punch in punch out times. They both have the gas card # referenced.
    I would like to go through each gas purchase and mainly find the ones that fall outside of work hours.


    There will be issues with purchases that have no corresponding data on the time sheet and vise-versa.
    The employees typically work overnights so the punch in and punch out times do have different dates often.


    Specifically, For each purchase on sheet "CC Data" (columns AF and AG) check to see if that purchase is within a time range on sheet "Time2" and then put the result in column AH on "CC Data". Either "Within Work Hours" "Outside Work Hours"" or "No Card Match".


    I am requesting a vba solution as this will be part of a userform project someone else is working on but if a formula is more elegant or efficient then that would be appreciated as well.


    Thanks in advance.

  • Thank you Brian.


    It works great in the temp WB but when i use it in the actual workbook it just hangs to the point i have to force close excel. the only thing that is different to my knowledge is a couple of extra sheets that shouldn't affect this code. in the original temp WB i trimmed out some of the data on the sheets but I don't see how that could effect the code you wrote. Unfortunately it doesn't error out to a particular line of code so i don't know how to try to evaluate the next step. I've attached the workbook as it is.

  • Brian,


    Thank you very much. I should have noticed that. It's been quite a while since I've messed with this kind of stuff.


    I am reminded though how helpful people here are and what an excellent site this is!


    Thanks again!


    Best Regards,

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!