Results 1 to 3 of 3

Vlookup in VBA only returns Error 1004

Threaded View

  1. #1
    Registered User
    Join Date
    11-13-2011
    Location
    San Ramon, Ca
    MS-Off Ver
    Excel 2003
    Posts
    6

    Vlookup in VBA only returns Error 1004

    I am working on a Userform and I want the user to enter their Zip Code and then I will look up the City and State. Below is the code I have been using.

    Private Sub Text_Zip_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    'MsgBox "this is the entered zip code " & Text_Zip & " end"

    Dim zip
    zip = Text_Zip.Text
    City = Application.WorksheetFunction.VLookup(zip, ThisWorkbook.Sheets("Sheet3").Range("A2:C11").Value, 2, False)
    MsgBox "The Zip Entered is " & zip
    MsgBox "The City is " & City

    End Sub

    However If I put an actual zip code in the VLookup statement see below it works perfectly. I can't figure out why with can't find a match when I try to use the input from the Userform.

    Private Sub Text_Zip_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    'MsgBox "this is the entered zip code " & Text_Zip & " end"

    Dim zip
    zip = Text_Zip.Text
    City = Application.WorksheetFunction.VLookup(94583, ThisWorkbook.Sheets("Sheet3").Range("A2:C11").Value, 2, False)
    MsgBox "The Zip Entered is " & zip
    MsgBox "The City is " & City

    End Sub

    I hope you can help me. I think it might have something to do with the variable being text and not number???
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Recorded Macro returns Run-time error '1004'
    By absconditus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-05-2015, 04:56 AM
  2. IF statement returns 1004 error when trying to add function to a cell using VBA
    By chairmaker in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-06-2013, 03:03 PM
  3. [SOLVED] VBA VLookup Error 1004
    By Ronny66 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-06-2013, 09:41 AM
  4. How to error trap a vlookup that returns an error or #N/A
    By kjy1989 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-06-2013, 12:01 PM
  5. VBA Vlookup returns 1004 error
    By Sportz234 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-15-2013, 03:08 PM
  6. VBA Code for IF Statement returns Run-Time Error 1004
    By esphero in forum Excel General
    Replies: 3
    Last Post: 03-22-2012, 07:06 AM
  7. cells.select returns error 1004
    By mqdias in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-03-2010, 04:21 AM

Tags for this Thread

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