The value of combobox1 is not shown on combobox2 when changing

sofas

Well-known Member
Joined
Sep 11, 2022
Messages
559
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Hello, I have two combobox elements on the user form whose data is fetched from the same column. What I am looking for is that when a specific value is chosen in combobox1, it is not automatically shown on combobox2. Can I do this dynamically?


VBA Code:
Private Sub UserForm_Initialize()
Set f = Sheets("Sh2")
  Set j = CreateObject("Scripting.Dictionary")
  a = f.Range("B4:B" & f.[B65000].End(xlUp).Row)
  For i = LBound(a) To UBound(a)
    If a(i, 1) <> "" Then j(a(i, 1)) = ""
  Next i
  n = j.keys
  Me.ComboBox1.List = n
  Me.ComboBox2.List = n
End Sub

Private Sub ComboBox2_Click()
''''Here I am trying to put a code that fetches the column data except the value on combobox1
End Sub
 

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
Maybe
VBA Code:
Private Sub ComboBox1_AfterUpdate()
    Set f = Sheets("Sh2")
    Set j = CreateObject("Scripting.Dictionary")
    a = f.Range("B4:B" & f.[B65000].End(xlUp).Row)
    For i = LBound(a) To UBound(a)
        If (a(i, 1) <> "") And (Format(a(i, 1), "@") <> Me.ComboBox1.Value) Then j(a(i, 1)) = ""
    Next i
    Me.ComboBox2.List = j.keys
    Set j = Nothing
End Sub
 
Last edited:
Upvote 0
Solution
Maybe
VBA Code:
Private Sub ComboBox1_AfterUpdate()
    Set f = Sheets("Sh2")
    Set j = CreateObject("Scripting.Dictionary")
    a = f.Range("B4:B" & f.[B65000].End(xlUp).Row)
    For i = LBound(a) To UBound(a)
        If (a(i, 1) <> "") And (Format(a(i, 1), "@") <> Me.ComboBox1.Value) Then j(a(i, 1)) = ""
    Next i
    Me.ComboBox2.List = j.keys
    Set j = Nothing
End Sub
Thank you, it works very efficiently
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
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