Hello,
I have several documents that contain data in one table (2 columns, row number varies) and I am trying to make a macro that loops through each row (starting from 3rd row) and copies the value of the 1st cell to the 2nd cell. Here's my current code:
Code:
Sub a_macro()
Dim d As Document. t As Table, r As Long, c As Long, rw As Row
Set d = ActiveDocument
Set t = d.Tables(1)
For r = 3 To t.Rows.Count
Set rw = t.Rows(r)
For c = 1 To rw.Cells.Count
If c = 1 Then
t.Cell(r, c).Range.Copy
ElseIf c = 2 Then
t.Cell(r, c).Range.PasteAndFormat (wdFormatOriginalFormatting)
End If
Next c
Next r
End Sub
But for some reason I'm getting error 4605 - "This command is not available." after copying and pasting 3 values. If I set the range to start from e.g. row 5, it succesfully copies and pastes the 3 next column 1 values. I've tried a few ways to loop the cells (hence the current is not the most elegant implementation) but the error keeps coming. The paste is what causes the error and when I run the code step-by-step with the debugger it runs without errors.
Any ideas how to fix this? I am using Word 2016.