+ Reply to Thread
Results 1 to 11 of 11

Returning different value in Dropdown List

  1. #1
    Registered User
    Join Date
    04-19-2010
    Location
    Calgary, AB
    MS-Off Ver
    Excel 2003
    Posts
    3

    Question Returning different value in Dropdown List

    Hello - I wonder if someone would please help me or point me to the right place with the below.

    I want to create an Excel Drop-Down menu with the below condition:
    - I have 4 items in columns A and B, respectively, as listed below:
    BVLV | Ball Valve
    BTLV | Butterfly Valve
    GVLV | Gate Valve
    GBLV | Globe Valve
    - The drop-down menu displays column B, however, upon selecting any item from this column, only the four-letter "valve code" from column A is returned.

    Alternatively, I can make a column C that displays both A and B together (merged, separated by a 'hyphen', and then make a drop-down list of this column C, but still wanted column A returned.

    The above is a simplified example from a list of hundreds of items. The reason I only needed the 4-letter code to be displayed because it will be exported to another form later on, and I didn't want the user to constantly refer back at the "source" data. I am not sure if exporting is possible if I select a 'combo-box' (either from Control or ActiveX), so I would prefer the normal Data Validation List method, since that has the "in-cell dropdown" option.

    Any help as to how to go about this would be much appreciated.

    Thanks very much.
    Last edited by skumars; 04-22-2010 at 04:02 AM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Returning different value in Dropdown List

    One way could be using VLOOKUP

    1/. Make a table as you have as you posted with your codes and descriptions

    2/. Name the right hand column say "ValveDesc"

    3/. Name the whole table say "ValvesData"

    4/. incell A2

    =IF(ISERROR(VLOOKUP(B2,ValveData,1)),"",VLOOKUP(B2,ValveData,1))

    Am I understanding you correctly?

  3. #3
    Forum Contributor wamp's Avatar
    Join Date
    11-10-2008
    Location
    Norway
    MS-Off Ver
    97, 2000 & 2003 (diff. workstations)
    Posts
    184

    Re: Returning different value in Dropdown List

    Have a look at the attached file for an example.
    Column A = the 4-letter shortword
    Column B = what should be displayed in the listbox.

    the sheet runs a macro called "changed" when someone changes the listbox value.
    Attached Files Attached Files

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Returning different value in Dropdown List

    skumars Have you have changed your user name to wamp
    and moved from Canada to Norway?......

  5. #5
    Forum Contributor wamp's Avatar
    Join Date
    11-10-2008
    Location
    Norway
    MS-Off Ver
    97, 2000 & 2003 (diff. workstations)
    Posts
    184

    Re: Returning different value in Dropdown List

    heh.. no. I just wrote my suggestion to him, and you allready posted while I did so.

    Your solution is probably a lot cleaner than mine :-)

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Returning different value in Dropdown List

    Sorry for the missunderstanding wamp

  7. #7
    Registered User
    Join Date
    04-19-2010
    Location
    Calgary, AB
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Returning different value in Dropdown List

    Thanks a bunch to the both of you for such quick help.

    Marcol: Your solution works partially, but it does not involve the drop-down listing that I was looking for.

    Wamp: The "change" macro that you provided is very close to what I am looking for. However, I do have additional questions as I try to learn this thing. So I was wondering what all VBA commands I need to change to apply this macro to my Worksheet...so still in progress on this one.

    And the other question I will likely face is how to replicate this macro for the whole column (your example sheet only shows it for one cell "F10").

  8. #8
    Forum Contributor wamp's Avatar
    Join Date
    11-10-2008
    Location
    Norway
    MS-Off Ver
    97, 2000 & 2003 (diff. workstations)
    Posts
    184

    Re: Returning different value in Dropdown List

    Hi again.
    it's hard to estimate your needs without a good example of the workbook..
    I do understand your questions, however there are many answers that might or might not suit your needs.

    Also you say you want to learn this *thumbsup*

    therefore:
    Look at the comments in the attached file.
    It's the same example as before, and I haven't changed the code itself, but explained what every lil'bit does. I've also added an example of what you can do.


    suggestion:
    in the "worksheet_change" routine, insert a breakpoint. (by pressing F9)
    the code will then break as soon as it runs. you can then itterate through each line of code by pressing F8.
    you will then see what each bit does, you can mouse-over the variables to see their values
    and then get a better understanding of how it all works.


    Hope this helps

    If you need any further information, please feel free to ask further

    However

    If this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody!
    Also
    If you are satisfied by any members response to your problem please consider using the scales icon top right of their post to show your appreciation.
    Attached Files Attached Files
    Last edited by wamp; 04-20-2010 at 04:30 AM.

  9. #9
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Returning different value in Dropdown List

    Hi All,

    Don't know if this is still relevent, but give it a look. No macros involved.

    1/. Add what you want to the list on Sheets("List") and notice it automatically updates the dropdown lists on Sheets("Sample").

    2/. To extend the list on Sheets("Sample").just use fill down, I have filled as far as Row 21 so just pick from Column A to get a code in Column C.

    Hope this of some help.

    P.S. Thanks to martinwilson this severe case of VBa I am suffering from, hopefully, is slowly on the mend!!!....
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    04-19-2010
    Location
    Calgary, AB
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Returning different value in Dropdown List

    Thanks again guys for the help & encouragement. I have marked this thread "Solved" but I do have quite a few questions I will be asking here as I get time (from work / to learn).

    For now, I just need a very quick help: In Wamp's example2 -- how do I refer to Source Data from another worksheet ??? I have already assigned 'Names' to the Source Data, which I refer to in the Data Validation List (=Name). Is it as simple as changing "sheet1" to "sheet2" ??
    =============

    As a general question that may or may not be related, say you have the below in VBA (from wamp's example2 file):

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Target.Column = 8 Then
    If (Len(Target.Value)) = 10 Then Exit Sub
    Run "Macro1"
    End If
    End Sub

    What if Target.Column and Target.Value is for Sheet1 but Macro1 that is being run has values from Sheet2 -- is that possible?? (does this question make sense?)

  11. #11
    Forum Contributor wamp's Avatar
    Join Date
    11-10-2008
    Location
    Norway
    MS-Off Ver
    97, 2000 & 2003 (diff. workstations)
    Posts
    184

    Re: Returning different value in Dropdown List

    Hi.

    to answer your question:
    the code in a worksheet_change will only execute on that specific worksheet.
    however, the code can get data from other worksheets
    question 2: macros can be run from anywhere. but if you are to get data from ranges from another sheet, you should select that sheet first, then go back
    see the following code for an example of what I mean (you can replace the code in my old example with this one)

    Please Login or Register  to view this content.
    Last edited by wamp; 04-22-2010 at 05:13 AM.

+ 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