Hi,
I have two workbooks and I need to match the first column of both of their first worksheet(ws1, ws2) first column(A). If match happens then it will return the matching row with 3 columns (A, F, AK) to the first worksheet. i have this Vlookup
=VLOOKUP(A2,'C:\Users\Temp\[Filename.xls]Sheet1'!$A$1:$C$65536,{1,2,3},FALSE)
Above v lookup works if I put the required columns consecutively (A,B, C) but i am not able to code into VBA.
Could you please help me in converting it to vba code,
Here is what I did,
myvar = ws2.Cells(i, 1)
myVLookupResult = WorksheetFunction.VLookup(myvar, 'C:\Users\Temp\Filename.xls}Sheet1'!$A$1:$C$65536,{1,2,3},FALSE)
but it isn't working. The data is big like there are 10000 lines to check, that's why "if and else" statements are not working. I also tried find and match
a = ws1.Cells(Rows.Count, 1).End(xlUp).Row
b = ws2.Cells(Rows.Count, 1).End(xlUp).Row
FindIn = Range("A2:A500").Value
For i = 2 To a
For k = 2 To b
ws1.Activate
cell = Application.Find(What:=Cells(i, 1).Value, After:=ws2.Cells(1, 1), LookIn:=ws2.Cells(k, 1).Value, LookAt:=xlWhole)
If Not cell Is Nothing Then
ws2.Activate
Union(Cells(k, 1), Cells(k, 4), Cells(k, 37)).Copy
ws1.Activate
Cells(i, 6).Select
ActiveSheet.Paste
Exit For
Else
Exit For
End If
Next k, i
I would appreciate the help
Thanks
I have two workbooks and I need to match the first column of both of their first worksheet(ws1, ws2) first column(A). If match happens then it will return the matching row with 3 columns (A, F, AK) to the first worksheet. i have this Vlookup
=VLOOKUP(A2,'C:\Users\Temp\[Filename.xls]Sheet1'!$A$1:$C$65536,{1,2,3},FALSE)
Above v lookup works if I put the required columns consecutively (A,B, C) but i am not able to code into VBA.
Could you please help me in converting it to vba code,
Here is what I did,
myvar = ws2.Cells(i, 1)
myVLookupResult = WorksheetFunction.VLookup(myvar, 'C:\Users\Temp\Filename.xls}Sheet1'!$A$1:$C$65536,{1,2,3},FALSE)
but it isn't working. The data is big like there are 10000 lines to check, that's why "if and else" statements are not working. I also tried find and match
a = ws1.Cells(Rows.Count, 1).End(xlUp).Row
b = ws2.Cells(Rows.Count, 1).End(xlUp).Row
FindIn = Range("A2:A500").Value
For i = 2 To a
For k = 2 To b
ws1.Activate
cell = Application.Find(What:=Cells(i, 1).Value, After:=ws2.Cells(1, 1), LookIn:=ws2.Cells(k, 1).Value, LookAt:=xlWhole)
If Not cell Is Nothing Then
ws2.Activate
Union(Cells(k, 1), Cells(k, 4), Cells(k, 37)).Copy
ws1.Activate
Cells(i, 6).Select
ActiveSheet.Paste
Exit For
Else
Exit For
End If
Next k, i
I would appreciate the help
Thanks