I have an almost perfectly functioning macro which matches rows in one table to another, and then imports any rows that aren't present in the source table onto the end of the destination table.
The ONLY problem i'm having, is that one section of the very last row that gets pasted gets correctly pasted, but then deleted again (i can see it get pasted very quickly before immediatly disappearing). There are some examples below.
[TABLE="width: 667"]
<colgroup><col span="4"><col><col span="3"></colgroup><tbody>[TR]
[TD="colspan: 4"] Source table
[/TD]
[TD][/TD]
[TD="colspan: 3"] Destination table
[/TD]
[/TR]
[TR]
[TD]Column1[/TD]
[TD]Column2
[/TD]
[TD]Column3[/TD]
[TD]Column4[/TD]
[TD][/TD]
[TD]Column1[/TD]
[TD]Column2[/TD]
[TD]Column3[/TD]
[/TR]
[TR]
[TD] A3
[/TD]
[TD] B3
[/TD]
[TD] -
[/TD]
[TD] C3
[/TD]
[TD][/TD]
[TD] A3
[/TD]
[TD] B3
[/TD]
[TD] C3
[/TD]
[/TR]
[TR]
[TD] A4
[/TD]
[TD] B4
[/TD]
[TD] -
[/TD]
[TD] C4
[/TD]
[TD][/TD]
[TD] A4
[/TD]
[TD] B4
[/TD]
[TD] C4
[/TD]
[/TR]
[TR]
[TD] A5
[/TD]
[TD] B5
[/TD]
[TD] -
[/TD]
[TD] C5
[/TD]
[TD][/TD]
[TD] A5
[/TD]
[TD] B5
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
As you can see, every value gets pasted correctly except for the very last one. (there is a break in the code which i made to skip column 3, as i dont want those values copied over. where the code jumps back in to start pasting values again is were the problem happens).
Thank you forany help and sorry for the janky post
The ONLY problem i'm having, is that one section of the very last row that gets pasted gets correctly pasted, but then deleted again (i can see it get pasted very quickly before immediatly disappearing). There are some examples below.
[TABLE="width: 667"]
<colgroup><col span="4"><col><col span="3"></colgroup><tbody>[TR]
[TD="colspan: 4"] Source table
[/TD]
[TD][/TD]
[TD="colspan: 3"] Destination table
[/TD]
[/TR]
[TR]
[TD]Column1[/TD]
[TD]Column2
[/TD]
[TD]Column3[/TD]
[TD]Column4[/TD]
[TD][/TD]
[TD]Column1[/TD]
[TD]Column2[/TD]
[TD]Column3[/TD]
[/TR]
[TR]
[TD] A3
[/TD]
[TD] B3
[/TD]
[TD] -
[/TD]
[TD] C3
[/TD]
[TD][/TD]
[TD] A3
[/TD]
[TD] B3
[/TD]
[TD] C3
[/TD]
[/TR]
[TR]
[TD] A4
[/TD]
[TD] B4
[/TD]
[TD] -
[/TD]
[TD] C4
[/TD]
[TD][/TD]
[TD] A4
[/TD]
[TD] B4
[/TD]
[TD] C4
[/TD]
[/TR]
[TR]
[TD] A5
[/TD]
[TD] B5
[/TD]
[TD] -
[/TD]
[TD] C5
[/TD]
[TD][/TD]
[TD] A5
[/TD]
[TD] B5
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
As you can see, every value gets pasted correctly except for the very last one. (there is a break in the code which i made to skip column 3, as i dont want those values copied over. where the code jumps back in to start pasting values again is were the problem happens).
HTML:
Sub ImportRows()
'declarations
Dim Val As String, SourceWs As Worksheet, DestWs As Worksheet, LastRowSource As Long, LastRowDest As Long
Set SourceWs = Sheets("Source")
'Activate Dest workbook
Set DestWs = Sheets("Dest")
LastRowSource = SourceWs.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
LastRowDest = DestWs.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'Declaring range to analyse
Dim i&, vSource, vDes
'"A2:A" = starting column, resize(, 1) = amount of columns to extend the range by
vSource = SourceWs.Range("A2:A" & LastRowSource).Resize(, 3).Value
vDes = DestWs.Range("B2:B" & LastRowDest).Resize(, 3).Value
'Source import
With CreateObject("Scripting.Dictionary")
For i = 1 To UBound(vDes, 1)
Val = (vDes(i, 1)) & (vDes(i, 2)) & (vDes(i, 3))
If Not .Exists(Val) Then
.Add Val, Nothing
End If
Next i
For i = 1 To UBound(vSource, 1)
Val = (vSource(i, 1)) & (vSource(i, 2)) & (vSource(i, 3))
If Not .Exists(Val) Then
'columns to copy
Intersect(SourceWs.Rows(i + 2), SourceWs.Range("A:A,B:B")).Copy
'columns to start pasting in
DestWs.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
'This next snippet likely contains the problem
'columns to copy
Intersect(SourceWs.Rows(i + 2), SourceWs.Range("C:C")).Copy
'columns to start pasting in
DestWs.Cells(Rows.Count, "C").End(xlUp).Offset(0, 0).PasteSpecial xlPasteValues
End If
Next i
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Thank you forany help and sorry for the janky post