Forum Discussion

sandrosg's avatar
sandrosg
Copper Contributor
Feb 04, 2023

Dropdown List with "description" and actual "value"

Hi there, 

 

I'm facing an issue with a dropdown list/menu. I need to create a simple KM calculation. However the KM(value) need to show its description (characters) in the dropdown menu. Any chance via the Data->Validation->List option? I'm enclosing 2 screens and a simple workbook. 

 

Thanks for your response 

 

6 Replies

  • Cangkir's avatar
    Cangkir
    Brass Contributor

    sandrosg 

    Here's another option, using vba & data validation:
    Helper range: $G$6:$G$8.

    Data validation formula: =$G$6:$G$8.
    On the Error Alert tab, uncheck mark on "Show error alert after invalid data is entered".
    In Sheet1 code window, put this code:

     

    Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo skip:
    
    If Target.Cells.CountLarge > 1 Then Exit Sub
        If Len(Target) = 0 Then Exit Sub
        
        If Not Intersect(Target, Range("F14:F16")) Is Nothing Then 'Range("F14:F16") is range with data validation
            Dim tx As String, c As Range, v
                tx = Target.Value
                If Len(tx) > 0 Then
                
                    If InStr(tx, " : ") Then
                        v = Split(tx, " : ")(1)
                        Else
                        v = Target.Value
                    End If
                    Application.EnableEvents = False
                    'Range("F6:F8") is col Distance
                    Set c = Range("F6:F8").Find(What:=v, LookIn:=xlValues, lookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
                        If Not c Is Nothing Then
                            Target = v
                        Else
                            MsgBox "Wrong Entry"
                            Target.ClearContents
                        End If
                   Application.EnableEvents = True
                   
                End If
     
        End If
    
    Exit Sub
    skip:
    Application.EnableEvents = True
    MsgBox "Error number " & Err.Number & " : " & Err.Description
    End Sub

     

     

     

    • sandrosg's avatar
      sandrosg
      Copper Contributor
      Hi Riny, this comes pretty close to my challenge. Is there any way to display just the numeric values in 1 cell ?I guess then it's getting more complex...anyway thx so far...
  • sandrosg 

    A simple workaround: display a data validation input message:

    Result:

    Otherwise, you'd either need a more complicated sum formula, or an ActiveX combo box together with VBA code.

Resources