© Matti Mattila, CPFA, CISA, CIA

Join Tables Excel Macro #2 (JoiTab2)

Previous item Next item Previous menu
Revised 16.08.2011

Purpose and functionality of 'JoiTab2'

The macro joins data of two tables (source tables: primary table; secondary table) into a third table (new table). Based on the match type you have three alternatives (not just one as in JoiTab1) what rows shall be written in the new file.

(1)

all rows of the primary table, and those rows of the secondary table, where the join key values match. Join key is the column value which the join is based on.

(2)

only those rows of source tables, where values of join key value match.

(3)

only those rows of the primary table, where the join key values do not match.

Because you have a possibility to select what table to use as a primary table and what to use as secondary table you have all theoretical table join options in use except 'join all rows in both source tables' [1].

The macro adds three columns after each line of the new table:
(i) 'PriRow': original row number of the primary table;
(ii) 'SecRow': orignal row number of the secondary table; and
(iii) 'MatCod': code describing the match: '1' = No match in secondary; '3' = Match.

The macro saves information about its run. Path and name of the workbook and worksheet of both source tables, and date and time of the run will be written on the third table, after the three [added] columns mentioned above.

The original tables remain unchanged.

The macro is more robust than its earlier version ('JoiTab1'). The format of key values can vary. Tables will be joined correctly even though key values would contain both numeric and string values mixed. And of course, key [strings] values can freely vary in lenght.

'JoiTab2'; download

You can download demo version of the macro here. Latest version of 'JoiTab' will be included in 'ExcAud' set of macros. A demo version of 'ExcAud' can be downloaded here.


[1] This option is not included in the macro, because it is needed rarely, and the desired result can be obtained through two runs of 'JoinTab2' (Basic run - 'All in primary'; then secondary as primary with 'Non-matches only').

'JoiTab2' is one of the macros of ExcAud.

JoiTab2

Test Design; starting the macro
01.03.2011
Selection of Primary Table and Key for Join
01.03.2011
Selection of Secondary Table
01.03.2011
The New Table
01.03.2011