reset button with combox

Bandito1

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

I got a combobox on my userform named cboxFunctionSearch
This combobox is filled with the following code;

Code:
Private Sub Init_cboxFunctionSearch()Dim X   As Integer
With Me.cboxFunctionSearch
    .Clear
    .AddItem "All"
    For X = 0 To Me.lstSearchResults.ListCount - 1
        Call addIfUnique(cboxFunctionSearch, CStr(Me.lstSearchResults.List(X, 3)))
    Next X
    .value = "All"
End With
End Sub


Public Sub addIfUnique(CB As ComboBox, value As String)
    If CB.ListCount = 0 Then GoTo doAdd
    Dim i As Integer
    For i = 0 To CB.ListCount - 1
        If LCase(CB.List(i)) = LCase(value) Then Exit Sub
    Next
doAdd:
    CB.AddItem value
End Sub

Now i try to make a reset button to reset this combobox after searching since in some cases the data in it disapear

I made a button and added the following code;

Code:
Private Sub cbtnReset_Click()
UserForm_Initialize
Init_cboxFunctionSearch
addIfUnique
End Sub

It crashes on addIfUnique, i think it's because it's a public sub?
How do i run above code to make this reset button work?
 

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
I don't think you need the addIfUnique line after Init_cboxFunctionSearch in the Reset code. First, addIfUnique is called from within Init. Second, addIfUnique requires parameters to be sent in: CB and value. You don't send anything, so it probably crashes here.

Remove it and see if it does what you want it to do.
 
Upvote 0

Forum statistics

Threads
1,224,787
Messages
6,180,950
Members
453,008
Latest member
GRTMAN

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