Link to home
Start Free TrialLog in
Avatar of FaheemAhmadGul
FaheemAhmadGulFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VBA Code to copy Text from different rows in one table to a single row in a different table

I had this question after viewing VBA Code to Copy and past text from multiple cells in one table to single cell in a different table.

The question I am asking will be very easy to understand if you look at the image included which shows data in two tables with data after the macro I need runs.

Basically I have two tables in a word document, each with two colums. Column 1 of Table 2 has some Titles, and Column 2 has Data. However, for some Titles there is no data in Column 2.
I would like the macro to copy both Title (from Column 1) and corresponding data from Colum 2, to a single row (Row 2) in Table 2, but only for thoses rows in Table 2 where there is some data in Column 2. That is those rows which only have a Title but not any data in Column 2 will not be copied to the row 2 of Table 1.

The data from the rows in Table 2 will be put in row 2 of Table 1, with a manual line break, but preserving the formating of the data.

User generated imageFor the sake of simplicity I have put only 8 Rows in Table 2. My actual Table 2 can have many more rows than this.
Thank you for your help.
Avatar of Norie
Norie

So you only want rows that have data in column 2 of Table2 to be copied to Table1?
Avatar of FaheemAhmadGul

ASKER

Yes please.
And these all need to be copied and pasted with formatting to row 2 of Table 1
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This code needs some modification as it is not giving the result we need. Please note that in this question (compared to the previous one you answered for me), we need to copy data from the column 2 of Table 2 also. Secondly we do not want to copy data (neither the title nor the data from Colum 2 of Table 2 rows) where there is no data in column 2. If you look at the image the rows with the Title, Super Markets, and Fruits have not been copied and that is because for these 3 rows we do not  have any data in Column 2.
This solution did not do exactly what my question had asked for, however, it did  give me some ideas through which I was able to solve the problem I was trying to solve.
Many thanks for your help. Greatly appreciated.