+ Reply to Thread
Results 1 to 9 of 9

vlookup in vba using named range

  1. #1
    Registered User
    Join Date
    06-24-2020
    Location
    Philadelphia, PA
    MS-Off Ver
    Office 365
    Posts
    28

    vlookup in vba using named range

    Hi Everyone - First time on this site! Can't figure this one out.

    Worksheet has 2 tabs. Data for user entry, Vehicles for my list of trucks. In VBA, want to lookup vehicle number in Data to verify its a valid number.
    Please Login or Register  to view this content.
    Get Compile error: Expected Function or variable

    Thanks
    Attached Files Attached Files
    Last edited by alansidman; 06-24-2020 at 06:40 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: vlookup in vba using named range

    Code Tags Added
    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: vlookup in vba using named range

    I see no relationship between your two sheets/tables. You will need to explain more specifically what your criteria is and what your expected results will look like based upon the data provided. We can work with Excel when we have complete data as we are not mind readers.

  4. #4
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: vlookup in vba using named range

    You are trying to return a value using a subroutine. You can only do that with a function.
    Change it to Function FindVehicle() and it will at least compile.

  5. #5
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: vlookup in vba using named range

    Maybe you want something like this ?
    Please Login or Register  to view this content.
    In VBA, want to lookup vehicle number in Data to verify its a valid number
    Please Login or Register  to view this content.
    Last edited by karmapala; 06-25-2020 at 02:38 PM.

  6. #6
    Registered User
    Join Date
    06-24-2020
    Location
    Philadelphia, PA
    MS-Off Ver
    Office 365
    Posts
    28

    Re: vlookup in vba using named range

    Hi karmapala

    Yes, that's what I am looking for, but can't seem to make it work. Compiles fine, just doesn't go the the MsgBox when entering a vehicle that is not in the list.

  7. #7
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: vlookup in vba using named range

    My bad. Very sorry about that.
    Please change this line :
    Please Login or Register  to view this content.
    into
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-24-2020
    Location
    Philadelphia, PA
    MS-Off Ver
    Office 365
    Posts
    28

    Re: vlookup in vba using named range

    That did it!! Thank you so much!
    Sluggy

  9. #9
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: vlookup in vba using named range

    You're welcome, Sluggy.
    Glad that I can help .

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Use Vlookup to insert a named range for the vlookup Table
    By thewholefoot in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-14-2018, 12:56 PM
  2. [SOLVED] VLOOKUP and Fill Handle Problem: Selected Range vs. Named Range
    By Menenius in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 01-12-2016, 08:50 PM
  3. Vlookup using Named Range
    By Renleff in forum Excel Formulas & Functions
    Replies: 27
    Last Post: 01-16-2014, 09:41 PM
  4. Excel 2007 : Help- Vlookup with Named Range
    By sus1 in forum Excel General
    Replies: 8
    Last Post: 06-04-2012, 11:49 PM
  5. Vlookup in a named range
    By tuph in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-28-2006, 09:23 PM
  6. Using named range in vlookup
    By lasca in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-02-2005, 10:16 AM
  7. Insert Vlookup into table_array of Vlookup with named range
    By Denise in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-24-2005, 07:06 PM

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