VBA- To Merge two sets based on a few criterias

shansakhi

Active Member
Joined
Apr 5, 2008
Messages
292
Office Version
  1. 365
Platform
  1. Windows
Dear All,
Need your assistance for below.

Khalid_COnnectivity_Working.xlsx
ABCDEFGHIJKLMNOPQRSTU
1Data Set 1Data Set 2
2DepDOWFrqAlnFLt NoDept StaDept TimeArvl StaArvl TimeTrafficDepDOWFrqAlnFlt NumDept StaDept TimeArvl StaArvl TimeTraffic
330-Dec-22Sun7VO102LHR20:05DEL07:15Inbound30-Dec-22Sun7VO331DEL14:10HYD18:25Outbound
431-Dec-22Sun7VO116FRA10:05DEL22:25Inbound30-Dec-22Sun7VO551DEL02:45MAa07:05Outbound
530-Dec-22Sun7VO124MUC21:45DEL06:50Inbound30-Dec-22Sun7VO125DEL11:50SXR18:50Outbound
631-Dec-22Sun7VO132CDG21:10DEL07:10Inbound1-Jan-23Sun7VO409DEL14:45CDG19:25Outbound
730-Dec-22Sun7VO145DEL08:10CHR18:20Outbound
830-Dec-22Sun7VO155DEL13:00ZRO19:05Outbound
930-Dec-22Sun7VO171DEL11:35ISO19:00Outbound
1031-Dec-22Sun7VO209DEL23:30FRS06:40Outbound
11
12OutPut
13Need to merge these two data sets with below criteria's
14> If difference between Arvl Time (Data set 1) and Dept Time (Data Set 2) ragning from 55 mins to 06 hours (Conx Time)
15> we shouold able to change the above differnec range if needed
16> If Arvl Time (Data set 1) is late in the night then the connection should be taken for next DEP day considering 55 Mins to 06 hours
17
18Examples
19DepDOWFrqAlnFLt NoDept StaDept TimeArvl StaArvl TimeTrafficConx TimeDepDOWFrqAlnFlt NumDept StaDept TimeArvl StaArvl TimeTraffic
2030-Dec-22Sun7VO102LHR20:05DEL07:15Inbound02:0030-Dec-22Sun7VO331DEL09:15HYD16:15Outbound
2130-Dec-22Sun7VO102LHR20:05DEL07:15Inbound00:5530-Dec-22Sun7VO551DEL08:10MAA04:10Outbound
2230-Dec-22Sun7VO124MUC21:45DEL06:50Inbound05:0030-Dec-22Sun7VO125DEL11:50SXR18:50Outbound
2330-Dec-22Sun7VO124MUC21:45DEL06:50Inbound01:2030-Dec-22Sun7VO145DEL08:10CHR18:20Outbound
2431-Dec-22Sun7VO132CDG21:10DEL07:10Inbound05:5030-Dec-22Sun7VO155DEL13:00ZRO19:05Outbound
2531-Dec-22Sun7VO132CDG21:10DEL07:10Inbound04:2530-Dec-22Sun7VO171DEL11:35ISO19:00Outbound
2631-Dec-22Sun7VO116FRA10:05DEL22:25Inbound04:001-Jan-23Sun7VO409DEL02:25BOM04:25Outbound
2731-Dec-22Sun7VO116FRA10:05DEL22:25Inbound01:0531-Dec-22Sun7VO209DEL23:30FRS06:40Outbound
28
Sheet3
 
Thank you.
The purpose of this data is.. If I select any flight number / Dept Sta and date from Data Set 1 then I should get the connecting flights from Data Set 2 corresponding to the selected details of Data Set 1. In actual data sets have more than 5000 rows. for example purpose we have taken a few rows.

Now hope data is meaningful.
Book2
ABCDEFGHIJKLMNOPQRSTUVWXY
1Data Set 1Data Set 2
2DepDOWFrqAlnFLt NoDept StaDepart DateTimeArrival DateTimeDept TimeArvl StaArvl TimeTrafficDepDOWFrqAlnFlt NumDept StaDepart DateTimeArrival DateTimeDept TimeArvl StaArvl TimeTraffic
330-Dec-22Sun7VO102LHR12/30/22 14:0512/30/22 22:1514:05DEL22:15Inbound31-Dec-22Sun7VO331DEL12/31/22 4:1512/31/22 8:1504:15HYD08:15Outbound
431-Dec-22Sun7VO116FRA12/31/22 10:0512/31/22 22:2510:05DEL22:25Inbound31-Dec-22Sun7VO551DEL12/31/22 3:1012/31/22 4:1003:10MAA10:10Outbound
530-Dec-22Sun7VO124MUC12/30/22 21:4512/31/22 6:5021:45DEL06:50Inbound31-Dec-22Sun7VO125DEL12/31/22 11:5012/31/22 18:5011:50SXR14:50Outbound
631-Dec-22Sun7VO132CDG12/31/22 21:101/1/23 7:1021:10DEL07:10Inbound1-Jan-23Sun7VO409DEL1/1/23 12:451/1/23 19:2512:45BOM19:25Outbound
730-Dec-22Sun7VO145DEL12/30/22 23:1512/31/22 3:2023:15CHR03:20Outbound
831-Dec-22Sun7VO155DEL12/31/22 12:5012/31/22 19:0512:50ZRO15:05Outbound
931-Dec-22Sun7VO171DEL12/31/22 11:3512/31/22 19:0011:35ISO14:00Outbound
1031-Dec-22Sun7VO209DEL12/31/22 23:301/1/23 6:4023:30FRS06:40Outbound
11
12OutPut
13Need to merge these two data sets with below criteria's
14> If difference between Arvl Time (Data set 1) and Dept Time (Data Set 2) ragning from 55 mins to 06 hours (Conx Time)
15> we shouold able to change the above differnec range if needed
16> If Arvl Time (Data set 1) is late in the night then the connection should be taken for next DEP day considering 55 Mins to 06 hours
17
18Examples
19DepDOWFrqAlnFLt NoDept StaDepart DateTimeArrival DateTimeDept TimeArvl StaArvl TimeTrafficConx TimeDepDOWFrqAlnFlt NumDept StaDepart DateTimeArrival DateTimeDept TimeArvl StaArvl TimeTraffic
2030-Dec-22Sun7VO102LHR12/30/22 14:0512/30/22 22:1514:05DEL22:15Inbound06:0031-Dec-22Sun7VO331DEL12/31/22 4:1512/31/22 8:1504:15HYD08:15Outbound
2130-Dec-22Sun7VO102LHR12/30/22 14:0512/30/22 22:1514:05DEL22:15Inbound04:5531-Dec-22Sun7VO551DEL12/31/22 3:1012/31/22 4:1003:10MAA10:10Outbound
2230-Dec-22Sun7VO102LHR12/30/22 14:0512/30/22 22:1514:05DEL22:15Inbound01:0030-Dec-22Sun7VO145DEL12/30/22 23:1512/31/22 3:2023:15CHR03:20Outbound
2331-Dec-22Sun7VO116FRA12/31/22 10:0512/31/22 22:2510:05DEL22:25Inbound01:0531-Dec-22Sun7VO209DEL12/31/22 23:301/1/23 6:4023:30FRS06:40Outbound
2430-Dec-22Sun7VO124MUC12/30/22 21:4512/31/22 6:5021:45DEL06:50Inbound05:0031-Dec-22Sun7VO125DEL12/31/22 11:5012/31/22 18:5011:50SXR14:50Outbound
2530-Dec-22Sun7VO124MUC12/30/22 21:4512/31/22 6:5021:45DEL06:50Inbound04:4531-Dec-22Sun7VO171DEL12/31/22 11:3512/31/22 19:0011:35ISO14:00Outbound
2630-Dec-22Sun7VO124MUC12/30/22 21:4512/31/22 6:5021:45DEL06:50Inbound06:0031-Dec-22Sun7VO155DEL12/31/22 12:5012/31/22 19:0512:50ZRO15:05Outbound
2731-Dec-22Sun7VO132CDG12/31/22 21:101/1/23 7:1021:10DEL07:10Inbound05:351-Jan-23Sun7VO409DEL1/1/23 12:451/1/23 19:2512:45BOM19:25Outbound
28
29
Sheet3
Cell Formulas
RangeFormula
M20:M27M20=T20-H20
Still makes no sense. Your example output starting at row 19 shows one flight departing multiple times. You're also using simple subtraction to determine Conx Time, but if the two date/times is more than one day, it won't be correct. In short, why are there multiple results/connections for one flight?
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Still makes no sense. Your example output starting at row 19 shows one flight departing multiple times. You're also using simple subtraction to determine Conx Time, but if the two date/times is more than one day, it won't be correct. In short, why are there multiple results/connections for one flight?
A single flight can have multiple connections. The purpose of this report to see how many connections each flight has.
We are restricting the connections from 0:55 mins to 6 hours.
 
Upvote 0
I attached another sample book. What it does is, it first generates all possible combinations of the first and second table. Then it filters connection times using advanced filter. It will allow you to input any time range you like.

Thank you.. This works but the only issue is that the formula doesn't look at the restriction of connection i.e. 0:55 mins to 06:00 hours.
When we use the formula on huge range it creating different possibilities over 6 hours as well.... which unable to fit in excel.
also, for more than 24 hours connections as well the formula gives conx time within 6 hours.
e.g. Data Set1 - Flight Arriving on 31st Oct 07:15 am shows conx with 4th Nov flight Departing at 09:00 am with 01:45 conx time. In actual the conx time is much more than 6 hours.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top