Reputation: 537
I am trying to put a whole worksheet in time order, but I have two time columns that control this. I would like to code a routine that will use both time columns together to create the first-level of the sort (kind of like a DB join?)
Columns A-C pertain to Train Schedules Columns D-F pertain to Truck loading and departure
Column B contains Train arrival times. Column F contains Truck departure times.
I would like to sort on both B and F simultaneously so that the whole worksheet is ordered in terms of the activities of the month. If I order by B first, all the train stuff will be at the top, and not mixed in time order with the truck activities. I want them mixed together.
So far, my only idea is to create a hidden column with the max of the dates in the time columns, and sort on that, but is there a technique to do the combination via code?
Thanks
Upvotes: 2
Views: 572
Reputation: 501
A few options:
1) A hidden column would be easiest - especially since VBA not have to be involved. 2) Another option would be a pivot table with a calculated field that combines them. 3) If you do want to use VBA, create a macro that inserts a new column at the front (range("A:A").Insert), have the macro combine the data, have it sort based on the new column A, then delete the column. A bit messy, but would get the job done. 4) If it's not going to break any other systems, you can include the date in the time column then show only the time by changing the column format. You can then sort by time without it changing things.
Upvotes: 1