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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,223,710
Messages
6,174,019
Members
452,542
Latest member
Bricklin

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