Highlighting Known Values In A Combobox List

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,648
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a combobox (IFM_title.lbx_smodel) on my userform that las a list populated by assigning it the values of a named range.
VBA Code:
IFM_title.lbx_smodel.List = Application.WorksheetFunction.Transpose(ThisWorkbook.names("modlist3").RefersToRange)
This large list contains names of animals in in.
On worksheet 3, I have a small list of animals occupying cells AB2 through AB4 (3 cells - Gorilla, Giraffe, Raccoon repectively. These 3 values exist in modlist3, and would be in the combobox's list.
How can I select (?) these three values in the combox list to highlight them?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi @Ark68

How can I select (?) these three values in the combox list to highlight them?

I assume you are referring to a ListBox, since in a combobox you cannot select multiple items.
1736783116557.png


Try this:

VBA Code:
Private Sub UserForm_Activate()
  Dim dic As Object
  Dim c As Range
  Dim i As Long
 
  Set dic = CreateObject("Scripting.Dictionary")
  For Each c In Sheets("Sheet3").Range("AB2:AB4")
    dic(c.Value) = Empty
  Next
 
  With IFM_title.lbx_smodel
    .List = Application.WorksheetFunction.Transpose(ThisWorkbook.Names("modlist3").RefersToRange)
    .MultiSelect = fmMultiSelectMulti
    For i = 0 To .ListCount - 1
      If dic.exists(.List(i)) Then
        .Selected(i) = True
      End If
    Next
  End With
End Sub

🧙‍♂️
 
Upvote 0

Forum statistics

Threads
1,225,444
Messages
6,185,013
Members
453,273
Latest member
Jeff Wyrick

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