I have several columns of dates, which I have distilled down into one master list, that contains all the dates each list has in common. Therefore any value in this list MUST be found in all the other columns.
I have several tables of data, across multiple sheets (which has dates in one column and values in the adjacent one), the columns of dates are fed from each table of data in these sheets, so these sheets may contain dates that are not found in the master list.
I want to copy and paste into adjacent columns, on each of these sheets, all the dates and their corresponding values that are contained in the master list.
Example (all listed on separate sheets, in range F13:GX)
(use sheet names of List 1, List 2, List 3 etc). All the sheets in the workbook will contain a list, apart from one called “Cover”).
List 1
22/12/2012 1
23/12/2012 2
24/12/2012 3
27/12/2012 4
28/12/2012 5
List 2
22/12/2012 2
23/12/2012 10
24/12/2012 11
28/12/2012 15
List 3
22/12/2012 2
23/12/2012 17
28/12/2012 22
29/12/2012 33
I want it to copy and paste the dates and values for
22/12/2012
23/12/2012
28/12/2012
for each list, and paste them into the range H13:I15
so i would have as the desired output.
List 1
22/12/2012 1 22/12/2012 1
23/12/2012 2 23/12/2012 2
24/12/2012 3 28/12/2012 5
27/12/2012 4
28/12/2012 5
List 2
22/12/2012 2 22/12/2012 2
23/12/2012 10 23/12/2012 10
24/12/2012 11 28/12/2012 15
28/12/2012 15
List 3
22/12/2012 2 22/12/2012 2
23/12/2012 17 23/12/2012 17
28/12/2012 22 28/12/2012 22
29/12/2012 33
There would be no blanks when values are skipped.
The simplest solution would be to use formulas rather than a macro.
For the example given, enter this formula in H3 of every “List” sheet:
=IFERROR(INDEX(MasterList,ROW()-ROW(F$13)+1),"")and this one in I3:
=IF(H13="","",INDEX(G:G,MATCH(H13,F:F,0)))Copy/fill the formula down as far as necessary.
MasterListis a Named Range referring to the master list of dates. A dynamic example, assuming the master list starts in cell A1 of a sheet named “Master” (with nothing else in the column), would be:=Master!$A$1:INDEX(Master!A:A,COUNTA(Master!A:A))You could, if so inclined, insert this directly into the first formula above.
Note: I kept the second formula above as simple as possible. As a result, it will break if there are any dates (or number equivalents) in the range F1:F12 matching the master list.
If you really want/need a macro solution the following “fairly simple” one should do the trick:
Important points:
Note: Since I presume you are already running a macro to generate the master list (doing so via formulas only would be difficult if not impossible), you could modify my macro to build the master list, like you currently do, before using it.
Alternatively, you could build and use it without actually saving it to a sheet. I would suggest loading all the “List” sheet data into an array of arrays, at the same time as building the master list using a dictionary. Then you loop over the array of arrays again, this time using the master list to generate the results.
EDIT:
This version of the macro allows for dates in the master list that are not in every one of the other lists.