+ Reply to Thread
Results 1 to 5 of 5

Best Way To Substitute Text From Drop Down List?

Hybrid View

  1. #1
    Registered User
    Join Date
    07-25-2010
    Location
    Blue Springs, MO
    MS-Off Ver
    Excel 2007
    Posts
    22

    Best Way To Substitute Text From Drop Down List?

    I have a list of approximately 100 products that I would like to give users a dropdown list to select from BUT while I want the list to show the product name I need the value placed into the cell to be its 5 to 7 character product code.

    Seems like something that should be possible but would really appreciate some direction in how to go about it.

    Thanks,
    Last edited by tradersteve; 10-19-2010 at 01:14 AM.

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Best Way To Substitute Text From Drop Down List?

    Possible you could adapt this excellent look up approach from Jerry Beaucaire

    Autocomplete Data Validation

    Download the sample file and give it a test drive.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  3. #3
    Registered User
    Join Date
    07-25-2010
    Location
    Blue Springs, MO
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Best Way To Substitute Text From Drop Down List?

    Thanks for the referral to the data validation samples. I'm afraid the best adaption I could come up with won't be nearly as elegant (or compact) as Mr. Beaucaire's sample but it will work if I make a really LONG drop down list and only go one level deep..

    Perfect would be if I could extend the validation out one more layer but I couldn't figure out how to write it.
    This code
    =IF(TRIM(B7)="",AlphaList,INDEX(NameList,IF(ISERROR(MATCH(LEFT(B7),NameList)),MATCH("*",NameList),MATCH(LEFT(B7),NameList)+1)):INDEX(NameList,MATCH(LEFT(B7)&REPT("z",3),NameList)))
    in data validation drills down from <Blank> to <D-names> to <individually listed names>. If its possible I would like help going one more list deep where the individual name would have a 1 item list under it containing the abbreviation code for that proper name. (i.e. Daniel = DG AB)

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Best Way To Substitute Text From Drop Down List?

    If VBA is viable you can use a Change Event on the DV cells to perform the lookup upon alteration and override the cell result
    (edit: this approach takes advantage of one of DV's flaws - a pasted value is not "validated")

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim rngI As Range, rngC As Range, vTemp As Variant
        On Error GoTo ExitPoint
        Application.EnableEvents = False
        Set rngI = Intersect(Target, Range("D1:D10"))
        If Not rngI Is Nothing Then
            For Each rngC In rngI.Cells
                With rngC
                    If .Value <> "" Then
                        vTemp = Application.VLookup(.Value, Range("A1:B10"), 2, 0)
                        .Value = IIf(IsError(vTemp), .Value, vTemp)
                    End If
                End With
            Next rngC
        End If
    ExitPoint:
        Set rngI = Nothing
        Application.EnableEvents = True
    End Sub
    the above is a very simplistic example but basically states that DV cells are D1:D10 and that DV source lookup table is A1:B10 where A1:A10 hold the values sourcing the DV list itself and B1:B10 represent the codes to be returned to the cell upon selection.
    Last edited by DonkeyOte; 10-17-2010 at 04:07 AM. Reason: revised with vTemp to account for pre-existing and then invalid selection

  5. #5
    Registered User
    Join Date
    07-25-2010
    Location
    Blue Springs, MO
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Best Way To Substitute Text From Drop Down List?

    Thanks to you both for the guidance. Both methods get me where I originally hoped to be but since the product list changes frequently it will probably be better to go the vba route for ease of changing the items in my list.

    THanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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