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)
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
here is the normal vlook up

=VLOOKUP(H2,'[Insurance Plans.xlsb]Ins Plan Number'!$B1:$C20000,2,0)
 
Upvote 0
here is the normal vlook up

=VLOOKUP(H2,'[Insurance Plans.xlsb]Ins Plan Number'!$B1:$C20000,2,0)

.Cells(rw, 18) = Application.VLookup(.Cells(rw, 18).Value2, x, 3, False)

Hi, can you spot the difference?

Shall anyone please help also instead of .Range("B1:C20000") am i able to use .Range("B1:B" & Ilastrow)


I think that you could use full column references with very little impact on performance, i.e.

Code:
Set x = extwbk.Worksheets("Ins Plan Number").Range("B:C")


 
Last edited:
Upvote 0
i did try with it and also i changed
.Cells(rw, 18) = Application.VLookup(.Cells(rw, 18).Value2, x, 2 False)

i am not sure why is this running blank
 
Upvote 0
Hi, can you post your updated code in full?
 
Upvote 0
this is my full code... am i missing something here

Hi, the code in post 1 is trying to return data from the 3rd column of a 2 column lookup table, in post 5 you imply that you have since changed it - can we see that changed code in full, copied directly from your workbook?
 
Last edited:
Upvote 0
Please see below it not working too.

[Dim wb As WorkbookDim 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, 18).Value2, x, 2, False)
Next rw
End With
extwbk.Close savechanges:=False
 
Upvote 0
Please see below it not working too.

What happens if you step through the code from the VBE using F8?

i am trying to get the values with the help of Vlook up once workbook gets opened

Are you trying to have this happen automatically when you open the workbook that contains the code? If so, the sub must be called:

Code:
Private Sub Workbook_Open()

And it must be in the "ThisWorkbook" module.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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