problem with clearing the combobox

excel_sat

New Member
Joined
Jun 10, 2015
Messages
22
hi

Pls sorry for the long post... but i really in need of a solution. so pls be patient with me

I have 2 dependent comboboxes. second one populates based on selection of first combobox.

My problem is.. I select the first combobox value. This results in population of second one.
when i type a value in the second combobox which is not present in the listed values i.e., any random text or garbage value, and then go back to first combobox, change the selection... This is not emptying the random text/garbage value i have typed in the second combobox.
Is there any way to insert some code to do this???
Below is my code:

populating values in First combobox:
Private Sub UserForm_Initialize()

With drpSearchBy
.AddItem "Emp ID"
.AddItem "Name"
.AddItem "Department"
End With
End Sub

populating values in second combobox: (i have used a sub createListByRef() to pull values from a sheet to populate)

Private Sub drpSearchBy_DropButt*******()
Dim rowCnt, index As Integer
Dim sh As Worksheet
Dim strRange As String
index = drpSearchBy.ListIndex
Set sh = Sheets("Forecast")
rowCnt = sh.UsedRange.Rows.count
drpSearchText.Clear
Select Case index
Case Is = 0
strRange = "B2:" + "B" & rowCnt
Call createListByRef(strRange)

Case Is = 1
strRange = "C2:" + "C" & rowCnt
Call createListByRef(strRange)

Case Is = 2
strRange = "D2:" + "D" & rowCnt
Call createListByRef(strRange)
End Select
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi,

Is there something preventing you from using : NameofyourSecondComboBox.Clear ???
 
Upvote 0
I tried using it after the select block but it clears out all the second comobobox data.
Iam not sure where to place it..

The above code works fine in clearing if i select a value from the dropdown list of combobox.The problem comes when i type something random other than the values listed and then change the 1st combo value.

Is there any other way to do it?
 
Last edited:
Upvote 0
Hello,

First, the good news ... using .Clear does clear the Combobox ...

Second, where to place ... since i do not know your code ... quite difficult to guess ... it should obviously be used exactly when you need it ...
From your description ... it seems that you need to place in the event : ComboBox1_Change()
 
Upvote 0
I have tried placing it in the ComboBox1_change() but to no use.

Is typing in and selecting the value of a combobox the same thing? If so then why is it clearing out when i select a value from dropdown but not when i type the value.

Is there a way to make this work?
 
Upvote 0
Not sure to fully understand what you are saying ...

As far as the modification is concerned ... typing or selecting a value from the dropdown ... does trigger the same change event ...
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,955
Latest member
BatCoder

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