Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2017, 01:18 AM
ffinley ffinley is offline Merging two tables in WORD with VBA Windows 7 32bit Merging two tables in WORD with VBA Office 2010 32bit
Novice
Merging two tables in WORD with VBA
 
Join Date: Dec 2015
Posts: 5
ffinley is on a distinguished road
Default 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:
  • Tables 1 and 2 each have four columns.
  • The first column in each table contains a country in each cell plus some other text behind them (i.e. in the same cell in the first column).
  • There are some countries (plus text) in table 1 which are not in table 2 and some in table 2 which are not in table 1.

About the intended merging of the tables:
  • I would now like to go through all the rows in each table and if the first 13 letters of the countries in column 1 of each table match, 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).
  • If the first 13 letters do not match I would like to still display the row and then leave the cell for the table which does not have this entry blank.

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
Reply With Quote
  #2  
Old 03-14-2017, 04:59 AM
macropod's Avatar
macropod macropod is offline Merging two tables in WORD with VBA Windows 7 64bit Merging two tables in WORD with VBA Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 03-14-2017, 11:32 AM
ffinley ffinley is offline Merging two tables in WORD with VBA Windows 7 32bit Merging two tables in WORD with VBA Office 2010 32bit
Novice
Merging two tables in WORD with VBA
 
Join Date: Dec 2015
Posts: 5
ffinley is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 03-14-2017, 07:43 PM
macropod's Avatar
macropod macropod is offline Merging two tables in WORD with VBA Windows 7 64bit Merging two tables in WORD with VBA Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply



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
Merging two tables in WORD with VBA Word - Merging from Access kevinegg45 Mail Merge 2 10-30-2012 09:10 AM
Merging two tables in WORD with VBA 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:58 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft