Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-07-2015, 03:39 AM
ffinley ffinley is offline Copying specific columns of a table to WORD and deleting rows Windows 7 32bit Copying specific columns of a table to WORD and deleting rows Office 2010 32bit
Novice
Copying specific columns of a table to WORD and deleting rows
 
Join Date: Dec 2015
Posts: 5
ffinley is on a distinguished road
Default Copying specific columns of a table to WORD and deleting rows

Dear all,

I would be very grateful if you could help me with a VBA code for this scenario:

I will select and copy A1 : D300 from Excel to the clipboard and, then, I would like to copy and paste (only!) columns 1 and 4 of this Excel table, i. e. A1 : A300 and D1 : D300, into columns 1 and 4 of a table of the exact same size in WORD with just one click.



After selecting and copying A1 : D300 in Excel, is it then possible (and what would be the VBA code) to have a VBA code in WORD basically doing the following:

1 - Go to Column 1 of the next table (there is only one table in the WORD document) and paste Column 1 of the table in the clipboard, and

2 - Go to Column 4 of the same table and paste Column 4 of the table in the clipboard

The WORD table is of the same size (i. e. 4 columns, 300 rows).

Afterwards, I would like the VBA code to go to each Row of the WORD table and delete all rows which contain a specific wording (let's say "abcd1234").

Thank you very much for your help with this.

Best regards,

Fin
Reply With Quote
  #2  
Old 12-07-2015, 04:21 AM
macropod's Avatar
macropod macropod is online now Copying specific columns of a table to WORD and deleting rows Windows 7 64bit Copying specific columns of a table to WORD and deleting rows 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

Is this process to be run from Word or Excel? How is the destination in Word to be identified?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-07-2015, 04:44 AM
ffinley ffinley is offline Copying specific columns of a table to WORD and deleting rows Windows 7 32bit Copying specific columns of a table to WORD and deleting rows Office 2010 32bit
Novice
Copying specific columns of a table to WORD and deleting rows
 
Join Date: Dec 2015
Posts: 5
ffinley is on a distinguished road
Default

Thanks for your swift reply. The process will be started from WORD, i. e. the steps would be:

1. [manually by user in EXCEL] Select and copy A1 : D300

2. [manually] Activate target WORD document

3. [VBA process linked with a button in WORD] Go to the target table, paste EXCEL column 1 to WORD table column 1, paste EXCEL column 4 to WORD table column 4.

Re. your second question: What would be the easiest way for you to identify the destination table in WORD? For me, any solution is fine. I could add a bookmark to the table - this is probably the best way to find it with VBA isn't it?

Thank you!!

Kind regards,

Fin
Reply With Quote
  #4  
Old 12-07-2015, 05:08 AM
macropod's Avatar
macropod macropod is online now Copying specific columns of a table to WORD and deleting rows Windows 7 64bit Copying specific columns of a table to WORD and deleting rows 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

That's not how a macro would normally work and making one do so would greatly complicate things.

Whether you're running the macro from Excel or Word, the process is much the same. Since the range is known, the macro might simply copy the contents of cells A1:A300 and D1300 to cells A1:A300 & B1:B300, respectively, of a designated Word table, omitting the unwanted rows.

The Word table might be designated by its index in the document (e.g. the 3rd table), but only if it will always be the 3rd table, or via a bookmark or some other unique indicator. Similarly the source worksheet might be identified by its name or position in the workbook.

You refer to activating the document; that isn't necessary. Using an Excel macro, provided the document is open, the data can be transferred without activating or selecting anything in it. If it's a known document that's closed, the macro can even open it - or create a new one from an appropriate template. Neither is activating the worksheet or selecting anything if the source range is known beforehand. Likewise, a Word macro can extract the data from either an open workbook or a closed one. However, it makes a significant difference as to how the macro is coded if you're running the macro from Excel or from Word. You need to say which you want to do.

Hence, there's no need for any manual processes; providing for them actually makes the coding far more complicated, since one has to suspend (not terminate) the macro's execution while the manual processes are done.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 12-07-2015, 05:22 AM
ffinley ffinley is offline Copying specific columns of a table to WORD and deleting rows Windows 7 32bit Copying specific columns of a table to WORD and deleting rows Office 2010 32bit
Novice
Copying specific columns of a table to WORD and deleting rows
 
Join Date: Dec 2015
Posts: 5
ffinley is on a distinguished road
Default

Thanks. Ok, in this case, I would prefer to run the process from Excel.

The Excel Macro should then select and copy A1 : D300, open a WORD document from a template (this template, however, cannot be stored in a location which can be accessed by all users of the Excel workbook; therefore, it would be good if we can "implement" the Word template into the Excel workbook - if this is not possible, I will find a way to store the Word template in a shared folder which everybody can access...), paste columns 1 and 4, delete rows with "abcd1234" in Column 1.

Many thanks,

Fin
Reply With Quote
  #6  
Old 12-07-2015, 04:01 PM
macropod's Avatar
macropod macropod is online now Copying specific columns of a table to WORD and deleting rows Windows 7 64bit Copying specific columns of a table to WORD and deleting rows 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

To be usable, a Word template must be accessible to the macro; otherwise you'd end up having to use the users default template - and coping with whatever customisations that has - then having to build the document from scratch using code. Aside from the complexities that entails, it would be much harder to maintain.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying specific columns of a table to WORD and deleting rows Mail Merge to create specific number of table rows flackend Mail Merge 4 12-01-2023 02:49 PM
Deleting info from specific table cells jamierbooth Word VBA 3 07-29-2014 03:20 PM
Copying specific columns of a table to WORD and deleting rows Deleting A blank Line that has a specific heading style , word 2010 & 2013 SteveWcg Word 5 01-08-2014 10:37 PM
Copying specific columns of a table to WORD and deleting rows Deleting rows with specific criteria joflow21 Excel 9 11-22-2013 12:10 PM
Adding columns in specific rows only mhays Excel 5 01-17-2012 09:13 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:50 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