ComboBox List selection to trigger code

MichaelRSnow

Active Member
Joined
Aug 3, 2010
Messages
409
Hi

Any know how to run code off the selection of a combobox list item i.e. as I type in a Combobox a list of items is populated, the list changes as I type more characters. When I then select an item using the mouse click so it populates what I've selected in the Combobox I want it to run some additional code.
Not as I type when the list changes but when I have selected an item, current code below

Any help would be gratefully received

VBA Code:
Private Sub ComboBox1_Change()

    Dim i As Long
 
    If Not IsArrow Then
        With Me.ComboBox1
            .List = Worksheets("MBDataLog").Range("Y2", Worksheets("MBDataLog").Cells(Rows.Count, "Y").End(xlUp)).Value
            .ListRows = Application.WorksheetFunction.Min(6, .ListCount)
            .DropDown
            If Len(.Text) Then
                For i = .ListCount - 1 To 0 Step -1
                    If InStr(1, .List(i), .Text, vbTextCompare) = 0 Then .RemoveItem i
                Next
                .DropDown
            End If
            'Debugging
        End With
    End If
 
  Sheets("MBDataChk").Range("B4").Value = ComboBox1
 
If ComboBox1.ListIndex > -1 Then

  TextBox7 = Sheets("MBDataChk").Range("A18").Value 'Email
  TextBox5 = Sheets("MBDataChk").Range("A23").Value 'Folder
  TextBox3 = Sheets("MBDataChk").Range("A19").Value 'Outcome
  TextBox4 = Sheets("MBDataChk").Range("A22").Value 'Team

    If Sheets("MBDataChk").Range("B1").Value = "" Then
    ListBox1 = Sheets("MBDataChk").Range("A24").Value
    Else
    End If

    If Sheets("MBDataChk").Range("B2").Value = "" Then
    ListBox2 = Sheets("MBDataChk").Range("A25").Value
    Else
    End If

    If Sheets("MBDataChk").Range("C2").Value = "" Then
    ListBox3 = Sheets("MBDataChk").Range("A27").Value
    Else
    End If

    TextBox14 = Sheets("MBDataChk").Range("A26").Value 'Email Date
    TextBox13 = Sheets("MBDataChk").Range("A27").Value 'Email Count

    If TextBox7.Text = "Yes" Then
        TextBox19.BackColor = RGB(112, 173, 71)
    ElseIf TextBox7.Text = "Yes by Exception" Or TextBox7.Text = "Yes with conditions" Or TextBox7.Text = "Refer to Lender" Then
        TextBox19.BackColor = RGB(255, 217, 102)
    ElseIf TextBox7.Text = "" Or TextBox7.Text = "More Detail/Information" Then
        TextBox19.BackColor = RGB(174, 170, 170)
    ElseIf TextBox7.Text = "No" Then
        TextBox19.BackColor = RGB(250, 67, 52)
    End If
   
Else
End If
 
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi

Any know how to run code off the selection of a combobox list item i.e. as I type in a Combobox a list of items is populated, the list changes as I type more characters. When I then select an item using the mouse click so it populates what I've selected in the Combobox I want it to run some additional code.
Not as I type when the list changes but when I have selected an item, current code below

Any help would be gratefully received

VBA Code:
Private Sub ComboBox1_Change()

    Dim i As Long
 
    If Not IsArrow Then
        With Me.ComboBox1
            .List = Worksheets("MBDataLog").Range("Y2", Worksheets("MBDataLog").Cells(Rows.Count, "Y").End(xlUp)).Value
            .ListRows = Application.WorksheetFunction.Min(6, .ListCount)
            .DropDown
            If Len(.Text) Then
                For i = .ListCount - 1 To 0 Step -1
                    If InStr(1, .List(i), .Text, vbTextCompare) = 0 Then .RemoveItem i
                Next
                .DropDown
            End If
            'Debugging
        End With
    End If
 
  Sheets("MBDataChk").Range("B4").Value = ComboBox1
 
If ComboBox1.ListIndex > -1 Then

  TextBox7 = Sheets("MBDataChk").Range("A18").Value 'Email
  TextBox5 = Sheets("MBDataChk").Range("A23").Value 'Folder
  TextBox3 = Sheets("MBDataChk").Range("A19").Value 'Outcome
  TextBox4 = Sheets("MBDataChk").Range("A22").Value 'Team

    If Sheets("MBDataChk").Range("B1").Value = "" Then
    ListBox1 = Sheets("MBDataChk").Range("A24").Value
    Else
    End If

    If Sheets("MBDataChk").Range("B2").Value = "" Then
    ListBox2 = Sheets("MBDataChk").Range("A25").Value
    Else
    End If

    If Sheets("MBDataChk").Range("C2").Value = "" Then
    ListBox3 = Sheets("MBDataChk").Range("A27").Value
    Else
    End If

    TextBox14 = Sheets("MBDataChk").Range("A26").Value 'Email Date
    TextBox13 = Sheets("MBDataChk").Range("A27").Value 'Email Count

    If TextBox7.Text = "Yes" Then
        TextBox19.BackColor = RGB(112, 173, 71)
    ElseIf TextBox7.Text = "Yes by Exception" Or TextBox7.Text = "Yes with conditions" Or TextBox7.Text = "Refer to Lender" Then
        TextBox19.BackColor = RGB(255, 217, 102)
    ElseIf TextBox7.Text = "" Or TextBox7.Text = "More Detail/Information" Then
        TextBox19.BackColor = RGB(174, 170, 170)
    ElseIf TextBox7.Text = "No" Then
        TextBox19.BackColor = RGB(250, 67, 52)
    End If
 
Else
End If
 
End Sub

Fyi the part of code that I want to run after selection of the item starts from "If ComboBox1.ListIndex > -1 Then" in the above code
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top