jkloucek
09-13-2016, 12:56 AM
Hi guys,
I'm getting an Overflow error (Error 6) and I just don't understand why.
I have two workbooks - one source WB and one target WS. The Source file has a significantly more items than the Target file.
What I wan't to do is to compare first columns of both WBs with IDs and if they match then other columns should copy from Source to Target WB.
The Overflow error is on line rowSource = rowSource + 1
Sub Copy()
Dim WB As Workbook
Dim WS As Worksheet
Set WB = Workbooks("HPD_product_export_EN_NEW.xlsx")
Set WS = WB.Sheets("Product Database")
Dim rowTarget As Integer
Dim rowSource As Integer
rowTarget = 1
rowSource = 1
Do
again:
If Cells(rowTarget, 1) = WS.Cells(rowSource, 1) Then
Cells(rowTarget, 10) = WS.Cells(rowSource, 10)
Else
rowSource = rowSource + 1
GoTo again
End If
rowTarget = rowTarget + 1
rowSource = 1
Loop Until rowTarget = 132
End Sub
Thanks for any advice in advance.
EDIT:// Ok after I posted this thread I found the solution. I did not realize, that a situation could happen when there is no match at all and the rowSource will be counting to infinity :) Just had to take care of that and that's it.
I'm getting an Overflow error (Error 6) and I just don't understand why.
I have two workbooks - one source WB and one target WS. The Source file has a significantly more items than the Target file.
What I wan't to do is to compare first columns of both WBs with IDs and if they match then other columns should copy from Source to Target WB.
The Overflow error is on line rowSource = rowSource + 1
Sub Copy()
Dim WB As Workbook
Dim WS As Worksheet
Set WB = Workbooks("HPD_product_export_EN_NEW.xlsx")
Set WS = WB.Sheets("Product Database")
Dim rowTarget As Integer
Dim rowSource As Integer
rowTarget = 1
rowSource = 1
Do
again:
If Cells(rowTarget, 1) = WS.Cells(rowSource, 1) Then
Cells(rowTarget, 10) = WS.Cells(rowSource, 10)
Else
rowSource = rowSource + 1
GoTo again
End If
rowTarget = rowTarget + 1
rowSource = 1
Loop Until rowTarget = 132
End Sub
Thanks for any advice in advance.
EDIT:// Ok after I posted this thread I found the solution. I did not realize, that a situation could happen when there is no match at all and the rowSource will be counting to infinity :) Just had to take care of that and that's it.