I want to copy the data present in A9, up to the cell A12 & similarly from B9 to B12. I can copy the data present in cell A1, up to A8 successfully. But cannot copy & paste from A9 to A12 & B9 to B12. My code is unable to copy & paste for the last record.
With wrdApp
.ActiveDocument.Tables(1).Select
.Selection.Copy
With ThisWorkbook.Worksheets("Sheet1")
.Cells(Rows.Count, "C").End(xlUp)(1).PasteSpecial xlPasteValues
'getting the last row
lastRow = .Range("C:C").End(xlDown).row
'loop all row in column "C" for checking
For row = 1 To lastRow Step 1
'If value of C cell is "Version", check column A cell and B cell
If (.Range("C" & row) = "Version" Or .Range("C" & row) = "version") Then
'If both cell are empty, store value.
If .Range("A" & row) = "" And .Range("B" & row) = "" Then
.Range("A" & row).Value = resultId
.Range("B" & row).Value = resultIdZ
LR = Range("B" & Rows.Count).End(xlUp).row
With Range("B2:B" & LR)
With .SpecialCells(xlCellTypeBlanks)
End With
.Value = .Value
End With
LR = Range("A" & Rows.Count).End(xlUp).row
With Range("A2:A" & LR)
With .SpecialCells(xlCellTypeBlanks)
.FormulaR1C1 = "=R[-1]C"
End With
.Value = .Value
End With
Exit For
End If
End If
Next row
End With
Here is my answer which might help someone. Prior to that, I would like to say thanks to Luuklag for helping me in a brilliant way.
Make sure that, you add the below references before proceeding.
You should try this. It pastes the values in A and B that are in the row next to were there is Version in column C as long as column C is not equal to version, and when it equals version it jumps to the next set of data.
It works now, it had a problem when it was in the row that had version in it and had columns a and b filled with data. Now it works:
Before:
After![enter image description here](https://i.stack.imgur.com/uhiuo.png)
Now inside your code: