combobox .additem

Bandito1

Board Regular
Joined
Oct 18, 2018
Messages
234
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I try to add items to my combobox with .additem

I notice that when i test it, it counts up.

So when i press A and after that B in cbo1 it shows 1, 2, 3 and 4 in cbo2.

It should only show 3 and 4 when i select B in cbo1 and only show 1 and 2 when i select A.

Someone knows how to do this?

VBA Code:
Private Sub cbo1_Change()
If cbo1.Value = "A" Then
    With cbo2
    .AddItem "1"
    .AddItem "2"
    End With
Else
    If cbo1.Value = "B" Then
    With cbo2
    .AddItem "3"
    .AddItem "4"
    End With
Else
    If cbo1.Value = "Tag(s)" Then
    With cbo2
    .AddItem "5"
    End With
    End If
    End If
    End If
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You just need to clear the array first. Please try:

VBA Code:
Private Sub cbo1_Change()

cbo2.Clear

If cbo1.Value = "A" Then
    With cbo2
    .AddItem "1"
    .AddItem "2"
    End With
Else
    If cbo1.Value = "B" Then
    With cbo2
    .AddItem "3"
    .AddItem "4"
    End With
Else
    If cbo1.Value = "Tag(s)" Then
    With cbo2
    .AddItem "5"
    End With
    End If
    End If
    End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,460
Messages
6,124,949
Members
449,198
Latest member
MhammadishaqKhan

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