Excel VBA loop slow

shakaib26

New Member
Joined
Feb 3, 2023
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

i have 80000 rows in "c"column with date in it. i am running below mentioned code to add the combobox list items on combobox change basis. When i run the macro it takes too long time on each change.

Can anybody suggest what to do to speed up the code.


Private Sub ComboBox2_Change()
Dim ws As Worksheet
Set ws = Worksheets("word by word")
Dim Lastrow, r, i As Long

For i = ComboBox2.ListCount - 1 To 0 Step -1
ComboBox2.RemoveItem i
Next i

Lastrow = ws.Range("c" & Rows.Count).End(xlUp).Row
For r = 3 To Lastrow
If InStr(ws.Cells(r, 3), ComboBox2.Text) > 0 Then
ComboBox2.AddItem (ws.Range("c" & r))

'code for showing list unique values only
Dim vArr()
ReDim vArr(1 To ComboBox2.ListCount)
vArr = ComboBox2.List
Dim e
With CreateObject("scripting.dictionary")
.comparemode = 1
For Each e In vArr
If Not .exists(e) Then .Add e, Nothing
Next
If .Count Then ComboBox2.List = (.keys)
End With

End If
If ComboBox2.Text = "" Then
ComboBox2.Clear
End If
Next r
End Sub
 
Actually combobox list is not showing all searched records only shows which have the search string in start but not showing the search string record which have it in middle or last part of name
Sorry, I don't understand your searching criteria, your explanation kind of confusing. So, please explain in more detail.
And one thing, do you need to search by 1 keyword only?
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Sorry, I don't understand your searching criteria, your explanation kind of confusing. So, please explain in more detail.
And one thing, do you need to search by 1 keyword only?
Hi
As per my sample excel sheet which i shared on mega.nz
there are two names in the coulumn C
"Khawaja Muhammad Shakaib" and "Ajief Khawaja"
now i search the keyword "Khawaja"
then in combobox list results it shows only "Khawaja Muhammad Shakaib" but not shows the "Ajief Khawaja"
this is the problem. and now search is case sensitive like it search only "Khawaja" but not search is typed "khawaja" in small letters.
Thanks
 
Upvote 0
Hi
Akuini
How are you?
Is it possible to search two or three words exits in difference places in a setense through combobox?

Example Setnese: The quick fox jumps over a lazy dog.
Search words: 1- dog 2- dox or 3- jumps
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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