+ Reply to Thread
Results 1 to 7 of 7

VLOOKUP in Worksheet_SelectionChange

Hybrid View

Boltsie VLOOKUP in... 07-05-2016, 06:35 AM
TMS Re: VLOOKUP in... 07-05-2016, 06:39 AM
xlnitwit Re: VLOOKUP in... 07-05-2016, 06:40 AM
Boltsie Re: VLOOKUP in... 07-05-2016, 01:09 PM
TMS Re: VLOOKUP in... 07-05-2016, 04:34 PM
Boltsie It was using... 07-05-2016, 04:44 PM
TMS Re: VLOOKUP in... 07-05-2016, 04:54 PM
  1. #1
    Registered User
    Join Date
    07-05-2016
    Location
    Nottingham
    MS-Off Ver
    2010
    Posts
    12

    VLOOKUP in Worksheet_SelectionChange

    Hi,

    Am I going mad? I just wish to pull some text from a range in my workbook depending on the number entered in the spreadsheet.

    Can anyone tell me why this isn't working please?

    strRegulationTxt = Application.WorksheetFunction.VLookup(Target.Value, Range("RegulationTable"), 2)

    Each time it comes up with error: Run Time error '1004' Method 'Range' of object '_Worksheet' failed.

    RegulationTable is a defined name in the workbook.

    Thanks for any help!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,492

    Re: VLOOKUP in Worksheet_SelectionChange

    Well, if you want it to do a lookup when you change a value, you probably need the Change event handler rather than the Selection Change event handler. And, if you want an exact match, you need to set the fourth parameter to False.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: VLOOKUP in Worksheet_SelectionChange

    Hi,

    If that named range is not on the sheet whose events you are using, you will get an error. Use Application.Range("RegulationTable") rather than simply Range.

  4. #4
    Registered User
    Join Date
    07-05-2016
    Location
    Nottingham
    MS-Off Ver
    2010
    Posts
    12

    Re: VLOOKUP in Worksheet_SelectionChange

    Thanks everyone. You have saved my problem! Simples when you know how!

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,492

    Re: VLOOKUP in Worksheet_SelectionChange

    You're welcome.

    Just out of interest, which answer resolved your problem? Or was it a combination?

  6. #6
    Registered User
    Join Date
    07-05-2016
    Location
    Nottingham
    MS-Off Ver
    2010
    Posts
    12
    Quote Originally Posted by TMS View Post
    You're welcome.

    Just out of interest, which answer resolved your problem? Or was it a combination?
    It was using application.range as the range wasn't in the active sheet. :-)

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,492

    Re: VLOOKUP in Worksheet_SelectionChange

    Ah, useful to know. Thanks.

+ 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. [SOLVED] Any way around Worksheet_selectionChange
    By banaanas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-16-2015, 12:08 AM
  2. Worksheet_SelectionChange
    By anghel.michael in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2011, 02:43 PM
  3. Worksheet_SelectionChange
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-17-2011, 10:26 AM
  4. Worksheet_SelectionChange
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-04-2011, 12:22 PM
  5. Sub Worksheet_SelectionChange
    By SuitedAces in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 12-28-2006, 05:29 AM
  6. [SOLVED] Worksheet_SelectionChange
    By Gary''s Student in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-05-2006, 04:50 AM
  7. Using Vlookup in Worksheet_SelectionChange
    By Brad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-25-2005, 06:50 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