Andreas Hermle
asked on
Code snippet to grab a cell content of a table cell using VBA
Dear Experts:
I would like to run a macro that performs the following task:
Go the very first table of the active document and copy the contents of the following cell into the clipboard: Column 4 and Row 1. After copying the cell contents into the clipboard delete the contents of that cell.
Help is much appreciated. Thank you very much in advance.
Regards, Andreas
I would like to run a macro that performs the following task:
Go the very first table of the active document and copy the contents of the following cell into the clipboard: Column 4 and Row 1. After copying the cell contents into the clipboard delete the contents of that cell.
Help is much appreciated. Thank you very much in advance.
Regards, Andreas
HI,
If you just want the content of the cell and not the cell then try
If you just want the content of the cell and not the cell then try
Sub Sample()
With ActiveDocument.Tables(1).Cell(1, 4)
Set rng = ActiveDocument.Range(.Range.Start, .Range.End - 1)
rng.Copy
.Range.Delete
End With
End Sub
Regards
ASKER
Dear both,
both codes work very fine. Thank you very much for it. Rgonzo, thank you for that specific feature.
In the meantime, the requirement of the macro code has changed.
Cell 4 should not be hard coded, but the last cell in row 1 of the very first table is always the cell where the macro is to work on (i.e. the tables vary in the number of columns). Would be great if either of you could change the code accordingly.
Thank you very much.
Regards, Andreas
both codes work very fine. Thank you very much for it. Rgonzo, thank you for that specific feature.
In the meantime, the requirement of the macro code has changed.
Cell 4 should not be hard coded, but the last cell in row 1 of the very first table is always the cell where the macro is to work on (i.e. the tables vary in the number of columns). Would be great if either of you could change the code accordingly.
Thank you very much.
Regards, Andreas
ASKER
Shums, thank you for your 'pasting' question. It is not relevant for the moment. Thank you, Regards, Andreas
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dear both, thank you very much for your professional help. I really appreciate it.
It is always hard to award points since both codes work just fine, but Rgonzo is more concise and therefore the majority of the points go to him. I hope you understand Shums :-)
Regards, Andreas
It is always hard to award points since both codes work just fine, but Rgonzo is more concise and therefore the majority of the points go to him. I hope you understand Shums :-)
Regards, Andreas
Open in new window
Do you want to paste somewhere?