Vlook Up not returning any Values

sg2209

Board Regular
Joined
Oct 27, 2017
Messages
117
Office Version
  1. 2016
Dear Friends ,
i am struggling with Vloook as i am new to VBA , i am trying to get the values with the help of Vlook up once workbook gets opened unfortunately not getting any values , its blank not sure what is wrong with the code

Sub Open_Workbooks()
Dim wb As Workbook
Dim lastrow As Long, i As Long
Dim rw As Long, x As Range
Dim extwbk As Workbook, twb As Workbook
Set twb = ThisWorkbook
Set extwbk = Workbooks.Open("Y:\Sachin Gupta\Cannon\Insurance Plans.xlsb")
Set x = extwbk.Worksheets("Ins Plan Number").Range("B1:C20000")
With twb.Sheets("Refund Payable report")
For rw = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
.Cells(rw, 18) = Application.VLookup(.Cells(rw, 18).Value2, x, 3, False)
Next rw
End With
extwbk.Close savechanges:=False

Shall anyone please help also instead of .Range("B1:C20000") am i able to use .Range("B1:B" & Ilastrow)
 
thank You everyone , i have read my code again and got the resolution myself 10 lines needs to be amended to Application.VLookup(.Cells(rw, 8 instead 18 and i got my results , please see the full code

Dim wb As Workbook
Dim lastrow As Long, i As Long
Dim rw As Long, x As Range
Dim extwbk As Workbook, twb As Workbook
Set twb = ThisWorkbook
Set extwbk = Workbooks.Open("Y:\Sachin Gupta\Byram\Insurance Plans.xlsb")
Set x = extwbk.Worksheets("Ins Plan Number").Range("B:C")
With twb.Sheets("Refund Payable report")
For rw = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
.Cells(rw, 18) = Application.VLookup(.Cells(rw, 8).Value2, x, 2, False)
Next rw
End With
extwbk.Close savechanges:=False
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
<article>
thank You everyone , i have read my code again and got the resolution myself 10 lines needs to be amended to Application.VLookup(.Cells(rw, 8 instead 18 and i got my results , please see the full code updated code

Dim wb As Workbook
Dim lastrow As Long, i As Long
Dim rw As Long, x As Range
Dim extwbk As Workbook, twb As Workbook
Set twb = ThisWorkbook
Set extwbk = Workbooks.Open("Y:\Sachin Gupta\Byram\Insurance Plans.xlsb")
Set x = extwbk.Worksheets("Ins Plan Number").Range("B:C")
With twb.Sheets("Refund Payable report")
For rw = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
.Cells(rw, 18) = Application.VLookup(.Cells(rw, 8).Value2, x, 2, False)
Next rw
End With
extwbk.Close savechanges:=False​
</article>


 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top