Hi
I assume the headings in the Result sheet correspond to the values in column B of the source sheet? if this is true try:
Option Explicit
Sub test()
Dim xlWs As Worksheet
Dim xlRng As Range
Dim i As Long, lngNextRow As Long
On Error GoTo test_ErrorHandler
Application.ScreenUpdating = False
Set xlWs = Worksheets("Result") 'adapt sheetname for target sheet
With ActiveSheet
For i = 2 To .Cells(.Rows.Count, 4).End(xlUp).Row
Select Case .Cells(i, 4).Value
Case "MATCH" 'from K
If .Cells(i, 11).Value <> 0 Then
Set xlRng = xlWs.Rows(1).Find(WHat:=.Cells(i, 2).Value, LookIn:=xlValues, lookat:=xlWhole)
If Not xlRng Is Nothing Then
xlWs.Cells(xlWs.Cells(xlWs.Rows.Count, xlRng.Column).End(xlUp).Row + 1, xlRng.Column).Value = .Cells(i, 11).Value
Else
Err.Raise vbObjectError + 512
End If
End If
Case "NO MATCH" 'from G
If .Cells(i, 8).Value <> 0 Then
Set xlRng = xlWs.Rows(1).Find(WHat:=.Cells(i, 2).Value, LookIn:=xlValues, lookat:=xlWhole)
If Not xlRng Is Nothing Then
xlWs.Cells(xlWs.Cells(xlWs.Rows.Count, xlRng.Column).End(xlUp).Row + 1, xlRng.Column).Value = .Cells(i, 8).Value
Else
Err.Raise vbObjectError + 512
End If
End If
Case Else
End Select
Next i
End With
test_Proc_Exit:
Application.ScreenUpdating = True
Exit Sub
test_ErrorHandler:
MsgBox "Error: " & Err.Number & " (" & Err.Description & ") in Sub 'test' of Module 'Module1'.", vbOKOnly + vbCritical, "Error"
Resume test_Proc_Exit
End Sub
Bookmarks