#1
|
|||
|
|||
Merging two tables in WORD with VBA
Dear all
Could you please help me with this scenario? I have two tables in WORD which I want to merge in the way described below. For ease of reference, I am calling the tables "TABLE 1" and "TABLE 2". About the tables:
About the intended merging of the tables:
Thank you very much for your help!! By the way: I picked 13 letters to identify the countries because there are no double entries then (and I do not have another possibility to identify them because the cells with the countries have a lot of other (varying) text so that I cannot just look for identical cells in tables 1 and 2). Best Fin |
#2
|
||||
|
||||
Are these two tables in the same document? If so, what separates them? What separates the country name from any other content that may be in the same cell (e.g. paragraph break, manual line break, tab)?
FWIW, the simplest way would be to merge the two tables into one, sort the merged table, then delete any duplicate rows (e.g. where the country names are the same).
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thanks -- the tables are not in one document (but I can, of course, copy them into one document if it is easier then to merge them).
There is, unfortunately, no certain character separating the country from the rest of the text (that's why I came up with the 13 characters - but that should not be a problem in VBA to see if the first 13 characters of two cells match...). Merging and sorting as you suggested does not work, unfortunately, because this would mean that I still have 4 columns... As I said, I would like to have 8 columns afterwards: "...then I would like to put column 1 of table 1, then column 1 of table 2, then column 2 of table 1, then column 2 of table 2, etc. (until all columns are next to each other, i.e. until column 4 of both tables)" So it is actually as easy as I said: - checking if we have a match in column 1 (first 13 characters) - if yes: putting column by column from each table - if no: putting column by column but leaving the cells of that table blank which did not have the country... Can anybody code this? Thank you. Best, Fin |
#4
|
||||
|
||||
It certainly wasn't clear from your post that you wanted to double the number of columns; the description could just as easily be met by adding a row and putting the new data on the row following the existing one.
The clarified description can certainly be met, but you need to provide more details about: • how the macro should locate/identify the two source files; • which file is to be regarded as holding the 'primary' table; and • what is to happen where there a country differences between the two files (e.g. do the unmatched data from the 'secondary' table get written to the newly-added secondary columns or to the primary columns? Do empty secondary columns get added to the 'primary' data when there are no secondary data). Your 'no' description is by no means clear about that.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Merging different documents in one big document keeping the chapters, figure numbers and tables | village | Word | 8 | 06-06-2016 04:16 AM |
Word - Merging from Access | kevinegg45 | Mail Merge | 2 | 10-30-2012 09:10 AM |
Avoid merging tables | b0x4it | Word | 4 | 06-14-2011 10:01 PM |
Merging Multiple Word files into One | Stattovic | Word | 0 | 01-06-2010 07:19 AM |
HELP! Merging Excel to Word | peevenjo | Mail Merge | 0 | 07-06-2007 03:24 PM |