Word Macro - Switch Values from table columns

Sarahmueller

New Member
Joined
May 17, 2020
Messages
24
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello,

I have a word document, in which results of medicinical tests are documented.

Several tables are part of the document. In these tables, the results of tests for the current and the last weeks are stored.

Afterwards, an assesment by the responsible doctor is provided. Therefore, I have to work with word, and can´t just use excel.

The tables are looking as follows:


Name of patient Current week1 weeks ago
Name 1XY
Name 2XY
Table 1: Medication 1 (week 1)

I have tried to write a macro that automatically switches the values of the columns after application, so that the table looks as follows:

Name of patientCurrent week1 week ago
Name 1X
X
Table 1: Medication 1 (week 2)


I have tried 2 solutions:
1) Edit the tables in Word with record a macro: Doesn´t work, because the selection always changes depending of the length of the doctors assessment
2) Insert tables from Excel into the word document (paste-special - excel worksheet object). I have also written excel makros to switch the columns, but I cant start the excel-macros automatically in word. I always have to double-click on the table, so that an excel worksheet opens and i have to manually activate the macro.

Therefore, i kindly ask you the following questions:

1) is it possible to write a macro in word to automatically edit word-tables?
2) Is ist possible to automatically run an macro in an embedded excel sheet from Microsoft word via vba?

Thank you in advance and stay healthy,

Sarah
 
I mean a code, so that table 1 in the document looks like this :
Header 1Header 2Header 3
Value Column 1Value Column 3
Value Column 1Value Column 3
Value Column 1Value Column 3


rather than this:
Header 1
Header 2Header 3
Value Column 1Value Column 2Value Column 3
Value Column 1Value Column 2Value Column 3
Value Column 1Value Column 2Value Column 3


I want to delete the value of all cells in the second column , except for the header :)

Thank you in advance and best regards,

Sarah
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Sorry, the layout of the first table changed after my post, of course the layout of the tables should remain identical (the correct layout is presented in the second table)
Best regards,
Sarah
 
Upvote 0
So how does this relate to the table in post #1 - or is this a completely different issue?
 
Upvote 0
This issue extends the main question, because the content of the cells not switched should be deleted.

Since I have already solved the problem, i will post my answer for interested readers:

You can directly edit a cell in a word table by using the following code:
VBA Code:
.Cell(Row, Column).Range.Text = "Example"

If you want to delete the content, just create a cell without content.
 
Upvote 0
What 'cells not switched'? As far as I can tell, that could only concern column 1 and deleting that content would result in patient details being deleted but their medications remaining in column 3.
 
Upvote 0

Forum statistics

Threads
1,214,618
Messages
6,120,544
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top