+ Reply to Thread
Results 1 to 6 of 6

Trouble Shooting VBA Vlookup

Hybrid View

Decoderman Trouble Shooting VBA Vlookup 04-14-2011, 11:55 AM
MarvinP Re: Trouble Shooting VBA... 04-14-2011, 12:11 PM
Decoderman Re: Trouble Shooting VBA... 04-14-2011, 12:14 PM
Decoderman Re: Trouble Shooting VBA... 04-14-2011, 12:17 PM
Decoderman Re: Trouble Shooting VBA... 04-14-2011, 12:18 PM
MarvinP Re: Trouble Shooting VBA... 04-14-2011, 12:28 PM
  1. #1
    Registered User
    Join Date
    12-15-2010
    Location
    Greenville, South Carolina
    MS-Off Ver
    Excel 2007
    Posts
    60

    Trouble Shooting VBA Vlookup

    Hello,

    I am still new to the vba world and still trying to figure out what will and will not work. I keep getting a "Type Mismatch" error on filez. Please Help!! And Thanks for your time!!

    
    Sub vlook()
    
    Dim strdir$
    Dim strfilename$
    Dim answer As String
    Dim filez As String
    Dim rangez As Range
    Dim rangez1 As Range
    
    
    Set rangez = Range("A3", "A" & Range("A3").End(xlDown).Row)
    Set rangez1 = Range("A3", "B" & Range("A3").End(xlDown).Row)
    
    
    
    
    strdir = "C:\Documents and Settings\smerdond.ittsys\My Documents\Testing\" 'file path
    strfilename = "book*.xls*" 'file name with file path
    filez = "'" & strdir & "[" & strfilename & "]" & "Sheet1'!" & rangez1
        
        For Each Cell In rangez
    
            answer = Application.WorksheetFunction.VLookup(Cell.Value, filez, 2, False)
            Cell.Offset(0, 1).Value = answer
    
        Next
    
    
    
    
    End Sub

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,378

    Re: Trouble Shooting VBA Vlookup

    Hi Decoderman,

    It looks like you are trying to build a string that starts with filez =.

    The problem is that you try to append at the very end of this line a Range.

    Ranges aren't strings. This gives a type mismatch. My best (first) guess.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    12-15-2010
    Location
    Greenville, South Carolina
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Trouble Shooting VBA Vlookup

    AHH I see what you mean.

  4. #4
    Registered User
    Join Date
    12-15-2010
    Location
    Greenville, South Carolina
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Trouble Shooting VBA Vlookup

    new code is
    Sub vlook()
    
    Dim strdir$
    Dim strfilename$
    Dim answer As String
    Dim filez As String
    Dim rangez As Range
    
    
    Set rangez = Range("A3", "A" & Range("A3").End(xlDown).Row)
    
    
    
    
    strdir = "C:\Documents and Settings\smerdond.ittsys\My Documents\Testing\" 'file path
    strfilename = "book*.xls*" 'file name with file path
    filez = "'" & strdir & "[" & strfilename & "]" & "Sheet1'!A:B"
        
        For Each Cell In rangez
    
            answer = Application.WorksheetFunction.VLookup(Cell.Value, filez, 2, False)
            Cell.Offset(0, 1).Value = answer
    
        Next
    
    
    
    
    End Sub
    Last edited by Decoderman; 04-14-2011 at 12:38 PM.

  5. #5
    Registered User
    Join Date
    12-15-2010
    Location
    Greenville, South Carolina
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Trouble Shooting VBA Vlookup

    I get the "Unable to run worksheet function" error... :-/

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,378

    Re: Trouble Shooting VBA Vlookup

    Now your filez is a string and it needs to be a range in the VLookup function.

    Study this http://www.functionx.com/vbaexcel/Lesson03.htm

    BTW - Edit your last post and put the code in Code Tags instead of Quote Tags.
    Last edited by MarvinP; 04-14-2011 at 12:32 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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