Hello,
i am working on a VBA that should find a match in the table column A of sheet 1 and match it in a table on sheet 2 and select column 6 cell value.
but when i run the code it selects the wrong row and value. what i'm i doing wrong.
i am working on a VBA that should find a match in the table column A of sheet 1 and match it in a table on sheet 2 and select column 6 cell value.
but when i run the code it selects the wrong row and value. what i'm i doing wrong.
Code:
Sub test()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim oCell As Range
Dim myArray() As Variant
i = 2
Set ws1 = ThisWorkbook.Sheets("Voeding")
Set ws2 = ThisWorkbook.Sheets("Waarde")
Do While ws1.Cells(i, 1).Value <> ""
Set oCell = ws2.Range("A:A").Find(What:=ws1.Cells(i, 1), LookIn:=xlValues, lookAt:=xlPart, SearchOrder:=xlByRows)
If Not oCell Is Nothing Then ws2.Cells(i, 6) = oCell.Offset(0, 1)
If IsNumeric(ws2.Cells(i, 6).Value) Then
ReDim Preserve myArray(x)
myArray(x) = Cells(i, 6).Value
myArray(x) = myArray(x) + 1
End If
i = i + 1
Loop
'Print values to Immediate Window (Ctrl + G to view)
For x = LBound(myArray) To UBound(myArray)
Debug.Print myArray(x)
Next x
Set ws1 = Nothing
Set ws2 = Nothing