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)
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)