Table of Contents

Visual Basic

Visual Basic is the language of especially Microsoft Excel.

Compare key columns A & C. Find where C=A. Copy value from column D to B

Sub test()

Dim cpk1 As Integer, cpk2 As Integer, cvnew As Integer, cvold As Integer, i As Integer, j As Integer

With Worksheets("test")
    i = 2167
    cpk1 = 2
    cpk2 = 10
    cvnew = 6
    cvold = 11
   
    
    For i = 1 To 3 '2167'
        For j = 1 To 3 '2167'
            
            If .Cells(i, cpk1).Value = .Cells(j, cpk2).Value Then  '.Cells(row, col) '
                MsgBox .Cells(i, cvnew).Value
                ' MsgBox .Cells(j, cvold).Value
                .Cells(i, cvnew).Value = .Cells(j, cvold).Value
                Exit For ' break loop'
            End If
        Next j
    Next i

 End With

End Sub