Comparing Trip Legs To and From

LearnVBA83

Board Regular
Joined
Dec 1, 2016
Messages
109
Office Version
  1. 365
Platform
  1. Windows
Hi VBA experts!

I have a big data set that shows where individuals went on daily trips using addresses. One column contains the To address and one column contains the from address. Obviously if Row 1 says From Address A to Address B then you'd expect Row 2 to start with From Address B To_____. Also, I want to see if the last trip for the day is the same address as the very start of the trip. For example: (FYI i'm using places instead of addresses and fake names)

Name Date/Time To Address From Address
John Doe 1/1/15 8AM Home WalMart
John Doe 1/1/15 9AM WalMart Dollar Store
John Doe 1/1/15 11AM Dollar Store Home
Billy Bob 1/1/15 9AM Home Bowling
Billy Bob 1/1/15 1PM Bowling Walgreens
Billy Bob 1/1/15 3PM Walgreens Home
Billy Bob 1/1/15 4PM Home Huddlehouse (I'd like for it to flag this because the daily trip didn't end at home)
Jane Doe 1/2/15 10AM Home Mall
Jane Doe 1/2/15 11AM Mall WalMart
Jane Doe 1/2/15 2PM Salon Home (I'd like for it to flag this because she wasn't at the Salon in her prior leg of the trip).


This is basically what my data looks like except real names and 100's of real addresses.

Please let me know if you think you could help!

Best!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
It's not pretty, but here's what you get :)

Also, this is based off of the below table, as I think your From and To columns were flipped.
Name
Date/Time
From Address
To Address
Discrepancy
John Doe
Home
Walmart
John Doe
Walmart
Dollar Store
John Doe
Target
Home
Discrepancy
Steven
Subway
Target
Steven
Bowling
Subway
Discrepancy

<TBODY>
</TBODY>

Keep in mind this formula will only work if all of the events from each person are in order. For example, all of the John Doe events must be in chronological order. If you have a John Doe, Steven, John Doe event like below;
Name
John Doe
Steven
John Doe

<TBODY>
</TBODY>
The formula will not work. I am sure someone will be along shortly to provide you a better solution. But this is my 2 cents.

This formula goes in the Discrepancy column and pasted down.
Code:
=IF(OR(A1="Name",A2<>A1),"",IF(AND(C2=D1,A2=A1),"","Discrepancy"))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

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