+ Reply to Thread
Results 1 to 2 of 2

VLookup fromula referencing a listbox and executed by a command button

  1. #1
    Registered User
    Join Date
    11-26-2012
    Location
    Utah USA
    MS-Off Ver
    Excel 2003
    Posts
    3

    VLookup fromula referencing a listbox and executed by a command button

    I have a user form with a list box and a command button. Am I able to program a VLOOKUP formula within the command button so that it looks up the selected value in the list box and returns the new value into the active cell on the worksheet?

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VLookup fromula referencing a listbox and executed by a command button

    A worksheet formula has no way to refer to a value selected in a listbox used on a userform. (If the listbox were in a worksheet you could use the LinkedCell attribute, but for some strange reason this attribute is not available in a listbox used on a userform.) I can think of two ways to do this.

    1. Crude but effective: Write a Change handler for the listbox so that every time a value is selected, that value is written to a cell someplace. This code goes into the userform module:
    Please Login or Register  to view this content.
    and change ListBox1 to the name of your list box, and also for the sheet and cell. Then your formula will look like

    =VLOOKUP(Sheet1!A1,A1:B10,2,FALSE)

    2. Impress your friends: Write a UDF to return the value. Create a new Module, and insert code like this:

    Please Login or Register  to view this content.
    Substitute your actual user form name and listbox name for MyUserForm.MyListBox.

    Now your worksheet formula will look something like this:

    =VLOOKUP(ListBoxValue,A1:B10,2,FALSE)
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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