Results 1 to 6 of 6

VBA code for Vlookup

Threaded View

  1. #1
    Registered User
    Join Date
    02-24-2015
    Location
    India
    MS-Off Ver
    MS Office 2013
    Posts
    3

    Post VBA code for Vlookup

    Hi everyone,

    I am trying to write vlookup code between two workbooks by browsing the file from the user.

    But Im getting error in the below line
    set lookfor= book1.Sheets(1).Range(Cells(3,4),Cells(Last row, 4))

    public Sub Command Button1_Click()
    pathTxtBox1.Text=""
    desPathName1 = Application.getOpenFilename()
    path.TxtBox1.Text = desPathName1
    End Sub
    
    
    public Sub Command Button2_Click()
    pathTxtBox1.Text=""
    desPathName2 = Application.getOpenFilename()
    path.TxtBox2.Text = desPathName2
    End Sub
    
    Public Sub Command Button3_Click()
    Dim fnameAndPath As Variant
    Dim fnameAndPath1 As Variant
    Dim book1 as Workbook
    Dim book2 as Workbook
    Dim lookfor as Range
    Dim ScrhRange as Range
    
    set book1 = Workbooks.Open(pathTxtBox1.Text,true, false)
    set book2 = Workbooks.Open(pathTxtBox2.Text,true, false)
    
    set lookfor= book1.Sheets(1).Range(Cells(3,4),Cells(Last row, 4))
    
    set ScrhRange = book2.Sheets(1).Range("A:D")
    
    lookfor.Offset(0,1).Value= Application.Vlookup(lookfor,srchRange, 2 , False)
    
    End sub
    It opens two files,but Im getting Application or object-defined error.Can anyone please help me to resolve this.


    Thanks in advance
    Last edited by alansidman; 02-26-2015 at 01:30 AM. Reason: code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 11-13-2013, 10:28 AM
  2. [SOLVED] VBA code for change vlookup formula to vlookup formula with ISNA
    By erprasannaa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2013, 03:33 AM
  3. Optimizing the Vlookup code in VB. Repitive code with different referencing range.
    By raknahs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-23-2010, 05:03 PM
  4. VLOOKUP using VBA code
    By Statsman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-09-2009, 02:59 AM
  5. vlookup in a VBA code?
    By tony0710 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-03-2009, 03:58 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1