I have 2 sheets, sheet2 have data consist of 5 columns I want to vlook up by vba code so the data from sheet2 with reference here is (ID) search in sheet1 and update the data from sheet 2 to sheet 1 like below. i have found a similar code but it updates only one column that is B cloumn i want to update C, D, E columns and rows by the below code, could anybody help in this. see the below code.
Sheet 2
Id, beginning, principal, interest, endbalance
123, 10000, 1000, 50 , 9000
789, 8000 , 400 , 150, 7600
245, 5000 , 1000, 200 , 4000
456, 4000 , 1000, 1000 , 3000
789, 2500 , 500 , 100 , 2000
Sheet1
id beginning principal interest endbalance
123 10000
789 8000
245 5000
456 4000
786 2500
Ifound below code suitable for the above query but this is only execute column b , I want to execute c, d, e columns how can I do this.
Sub ADDCLM()
On Error Resume Next
Dim Dept_Row As Long
Dim Dept_Clm As Long
ctr = 0
Table1 = Sheet1.Range("A3:A10") ' Employee_ID Column from Employee table
Table2 = Sheet2.Range("a3:e10") ' Range of Employee Table 1
Dept_Row = Sheet1.Range("b3").Row '
Dept_Clm = Sheet1.Range("b3").Column
For Each cl In Table1
Sheet1.Cells(Dept_Row, Dept_Clm).FormulaR1C1 = "=VLOOKUP(RC[-1],sheet2!C[-1]:c,2, False)"
Dept_Row = Dept_Row + 1
ctr = ctr + 1
Next cl
MsgBox "Done"
End Sub
Sheet 2
Id, beginning, principal, interest, endbalance
123, 10000, 1000, 50 , 9000
789, 8000 , 400 , 150, 7600
245, 5000 , 1000, 200 , 4000
456, 4000 , 1000, 1000 , 3000
789, 2500 , 500 , 100 , 2000
Sheet1
id beginning principal interest endbalance
123 10000
789 8000
245 5000
456 4000
786 2500
Ifound below code suitable for the above query but this is only execute column b , I want to execute c, d, e columns how can I do this.
Sub ADDCLM()
On Error Resume Next
Dim Dept_Row As Long
Dim Dept_Clm As Long
ctr = 0
Table1 = Sheet1.Range("A3:A10") ' Employee_ID Column from Employee table
Table2 = Sheet2.Range("a3:e10") ' Range of Employee Table 1
Dept_Row = Sheet1.Range("b3").Row '
Dept_Clm = Sheet1.Range("b3").Column
For Each cl In Table1
Sheet1.Cells(Dept_Row, Dept_Clm).FormulaR1C1 = "=VLOOKUP(RC[-1],sheet2!C[-1]:c,2, False)"
Dept_Row = Dept_Row + 1
ctr = ctr + 1
Next cl
MsgBox "Done"
End Sub
Last edited: