• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to program the after no selection?

Dear Experts

I have a question here. I have created a selection list that says no to the Fruit Items.
How to create that in VBA programming? Hope to hear from you soon.

Thanks.
 

Attachments

  • Multiple-Selection-from-a-Drop-Down-List-in-Excel.xlsm
    15.1 KB · Views: 9
Code:
Sub test()
    With Cells(3, 5).Validation
        .Delete
        .Add Type:=xlValidateList, Formula1:="=$A$2:$A$3"
    End With
    With Cells(6, 5).Validation
        .Delete
        .Add Type:=xlValidateList, Formula1:="=$C$2:$C$6"
    End With
End Sub
 
Use a standard code module
 

Attachments

  • Multiple-Selection-from-a-Drop-Down-List-in-Excel.xlsm
    17.8 KB · Views: 6
Dear RDAngelo

Thanks for your Excel attachment.

The Purchase Fruit, if select "no" it should freeze the fruit items selection.

Hope that helps.
 
Replace the code in the worksheet module with this...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Oldvalue As String, Newvalue As String

    Application.EnableEvents = True
    If Not Intersect(Target, Range("E6")) Is Nothing Then
        Application.EnableEvents = False
        If Range("E3").Value = "Yes" Then
            Newvalue = Target.Value
            Application.Undo
            Oldvalue = Target.Value
            If Oldvalue = "" Then
                Target.Value = Newvalue
            Else
                If InStr(1, Oldvalue, Newvalue) = 0 Then
                    Target.Value = Oldvalue & ", " & Newvalue
                Else:
                    Target.Value = Oldvalue
                End If
            End If
        Else
            Target.Value = vbNullString
        End If
    End If
    Application.EnableEvents = True
End Sub
 
Back
Top