BenChod
06-03-2017, 07:23 AM
Hello All -
I am using the following vlookup method in VBA to look up a value in the main table to a reference table in another worksheet. When there is match, copy that value in column A. For some reason, the copying is not working and I am hoping someone can tell me what I am doing wrong.
Sub VLookup()
On Error Resume Next
Dim table1 As Range
Dim table2 As Range
Dim cl As Range
Worksheets("QC").Activate
Range("A1").EntireColumn.Insert
Cells(1, 1) = "Env"
table1 = Worksheets("QC").Range("Y2:Y3000") ' Originating App from QC Table
table2 = Worksheets("ReferenceData").Range("A2:B20") ' Range of Reference Data Tabe
type_row = Worksheets("QC").Range("A2").Row ' Change A2 with the cell from where you need to start populating the Department
type_col = Worksheets("QC").Range("A2").Column
For Each cl In table1
Worksheets("QC").Cells(type_row, type_col) = Application.WorksheetFunction.VLookup(cl, table2, 2, False)
type_row = type_row + 1
Next cl
End Sub
I am using the following vlookup method in VBA to look up a value in the main table to a reference table in another worksheet. When there is match, copy that value in column A. For some reason, the copying is not working and I am hoping someone can tell me what I am doing wrong.
Sub VLookup()
On Error Resume Next
Dim table1 As Range
Dim table2 As Range
Dim cl As Range
Worksheets("QC").Activate
Range("A1").EntireColumn.Insert
Cells(1, 1) = "Env"
table1 = Worksheets("QC").Range("Y2:Y3000") ' Originating App from QC Table
table2 = Worksheets("ReferenceData").Range("A2:B20") ' Range of Reference Data Tabe
type_row = Worksheets("QC").Range("A2").Row ' Change A2 with the cell from where you need to start populating the Department
type_col = Worksheets("QC").Range("A2").Column
For Each cl In table1
Worksheets("QC").Cells(type_row, type_col) = Application.WorksheetFunction.VLookup(cl, table2, 2, False)
type_row = type_row + 1
Next cl
End Sub