Hi all,
I am trying to finish off a VBA If statement but am struggling to find if its possible to match to the closest time to finalise a copy and paste.
Essentially the code looks through some data I have organised and says;
If a cell in Sheet1.Column A = Sheet2.Column A then
if Sheet1.Column B = Sheet2.Column B then
if Sheet1.Column C = Sheet2.Column C then
Copy those cells that match to Sheet 2 Columns X,Y, Z
The logic is that by structuring it like this the code will make sure that all 3 conditions are met in order before copying and pasting.
Column A + B could have the same data further in the data set, where column C is realistically the defining factor to kick off the copy and paste.
The thing is is that Column C is a time....
Sheet2. Column C is always a round number eg: 9:00 AM, 11:30AM, 6:00PM
But
Sheet1. Column C is a "real number" eg: 10:36:58 AM, 6:58:31 PM
and so I want to that If statement for Column C to go "this number is close enough (could be slightly earlier or slightly after) to what I'm looking for and therefore thats okay"
If anyone has the answer I would be super grateful!
Thank you
Sheet 1 layout
Sheet 2 layout
Expected output
I am trying to finish off a VBA If statement but am struggling to find if its possible to match to the closest time to finalise a copy and paste.
Essentially the code looks through some data I have organised and says;
If a cell in Sheet1.Column A = Sheet2.Column A then
if Sheet1.Column B = Sheet2.Column B then
if Sheet1.Column C = Sheet2.Column C then
Copy those cells that match to Sheet 2 Columns X,Y, Z
The logic is that by structuring it like this the code will make sure that all 3 conditions are met in order before copying and pasting.
Column A + B could have the same data further in the data set, where column C is realistically the defining factor to kick off the copy and paste.
The thing is is that Column C is a time....
Sheet2. Column C is always a round number eg: 9:00 AM, 11:30AM, 6:00PM
But
Sheet1. Column C is a "real number" eg: 10:36:58 AM, 6:58:31 PM
and so I want to that If statement for Column C to go "this number is close enough (could be slightly earlier or slightly after) to what I'm looking for and therefore thats okay"
If anyone has the answer I would be super grateful!
Thank you
Sheet 1 layout
Type | Tracking Start Date | Tracking Start Time |
Truck 1 | 3/28/22 | 10:36:58 AM |
Truck 1 | 3/28/22 | 7:18:42 PM |
Truck 1 | 3/29/22 | 8:58:36 AM |
Truck 1 | 3/30/22 | 9:34:36 AM |
Truck 1 | 3/30/22 | 9:46:18 AM |
Truck 1 | 3/30/22 | 10:44:12 AM |
Sheet 2 layout
Type | Booking Start Date | Booking Start Time |
Truck 1 | 3/27/22 | 6:00:00 AM |
Truck 1 | 3/28/22 | 10:30:00 AM |
Truck 1 | 3/28/22 | 6:00:00 PM |
Truck 1 | 3/30/22 | 8:00:00 AM |
Truck 1 | 3/30/22 | 11:00:00 AM |
Truck 1 | 3/30/22 | 1:30:00 PM |
Expected output
Type | Booking Start Date | Booking Start Time | Booking End Time | Booking End Date | Tracking Start Date | Tracking Start Time |
Truck 1 | 3/27/22 | 6:00:00 AM | 12:00:00 AM | 3/28/22 | No Matching Data | No Matching Data |
Truck 1 | 3/28/22 | 10:30:00 AM | 3:30:00 PM | 3/28/22 | 3/28/22 | 10:36:58 AM |
Truck 1 | 3/28/22 | 6:00:00 PM | 6:00:00 PM | 3/29/22 | 3/28/22 | 7:18:42 PM |
Truck 1 | 3/30/22 | 8:00:00 AM | 10:30:00 AM | 3/30/22 | 3/30/22 | 9:34:36 AM |
Truck 1 | 3/30/22 | 11:00:00 AM | 1:00:00 PM | 3/30/22 | 3/30/22 | 10:44:12 AM |