Reputation: 834
I have a table in Word and I need to move certain rows to the bottom of the table using VBA.
I know I can do this by cutting and pasting (myTable.Rows(2).Select ... Selection.Cut ... etc.
) but I don't want to have to use the clipboard.
Although I can manually highlight the row and drag it using the mouse, when I record a macro, the drag is not allowed and there does not seem to be any obvious menu instruction to carry out the equivalent.
The only other thing I can think of doing is (using VBA):
A "sexier" solution to this must be out there ;)
Upvotes: 0
Views: 289
Reputation:
Here are two things you could explore:
Use FormattedText:
Sub moverow4table1toend()
Dim source As Word.Range
Dim target As Word.Range
Dim t As Word.Table
Set t = ActiveDocument.Tables(1)
Set target = t.Range
target.Collapse wdCollapseEnd
Set source = t.Rows(4).Range
target.FormattedText = source.FormattedText
source.Rows(1).Delete
Set source = Nothing
Set target = Nothing
Set t = Nothing
End Sub
Or perhaps if you are actually doing something more like sorting, you could add a column (assuming you haven't reached the limit, populate it with the destination row numbers, sort the table, and remove the column.
Upvotes: 1