Userform Text Input slows down

Guard913

Board Regular
Joined
Apr 10, 2016
Messages
144
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
So I am pretty sure I know why it is slowing down, and my hope is to find out how to speed it back up without changing the excel table info, and I have no control over changing it.

Works Fine (Good Speed)
VBA Code:
Private Sub CboOfferCode_Change()
Dim ws As Worksheet
Dim x, dict
Dim i As Long
Dim str As String
Set ws = Sheets("Lists")
x = ws.Range("Offer_Code").Value
Set dict = CreateObject("Scripting.Dictionary")
str = Me.CboOfferCode.Value
If str <> "" Then
    For i = 1 To UBound(x, 1)
        If InStr(LCase(x(i, 1)), LCase(str)) > 0 Then
            dict.Item(x(i, 1)) = ""
        End If
    Next i
    Me.CboOfferCode.List = dict.keys
Else
    Me.CboOfferCode.List = x
End If
Me.CboOfferCode.DropDown
Worksheets("Prom Codes").Range("H2") = Me.CboOfferCode.Value

    With Sheets("Prom Codes")
 
    .Range("A1:E507").AutoFilter Field:=1, Criteria1:=.Range("H2").Value
 
    End With
    
     CommandButton12.Enabled = True
End Sub

Takes time for text to show after typing
VBA Code:
Private Sub CboItem_Change()
Dim ws As Worksheet
Dim x, dict
Dim i As Long
Dim str As String
Set ws = Sheets("Lists")
x = ws.Range("Item").Value
Set dict = CreateObject("Scripting.Dictionary")
str = Me.CboItem.Value
If str <> "" Then
    For i = 1 To UBound(x, 1)
        If InStr(LCase(x(i, 1)), LCase(str)) > 0 Then
            dict.Item(x(i, 1)) = ""
        End If
    Next i
    Me.CboItem.List = dict.keys
Else
    Me.CboItem.List = x
End If
Me.CboItem.DropDown
Worksheets("Rates").Range("N24") = Me.CboItem.Value

    With Sheets("Rates")
 
    .Range("A1:L280242").AutoFilter Field:=2, Criteria1:=.Range("N24").Value
 
    End With

CboTerm.Enabled = True

End Sub

I am almost certain that this part is causing it: (Because of how big the range is)
(And I have no control of size of Range so everything I do has to work with what is on hand, I can only control how the Userforms are set up.)

VBA Code:
     With Sheets("Rates")
 
    .Range("A1:L280242").AutoFilter Field:=2, Criteria1:=.Range("N24").Value
 
    End With

And this one works fine because it has a much lower range to contend with.
VBA Code:
    With Sheets("Prom Codes")
 
    .Range("A1:E507").AutoFilter Field:=1, Criteria1:=.Range("H2").Value
 
    End With
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
how about declaring a Long variable like lastRow?

VBA Code:
Sub hi()
Dim lastRow As Long
    With Sheets("Rates")
        lastRow = .Cells(.Rows.Count, "L").End(xlUp).Row
        .Range("A1:L" & lastRow).AutoFilter Field:=2, Criteria1:=.Range("N24").Value
    End With
    With Sheets("Prom Codes")
        lastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
        .Range("A1:E" & lastRow).AutoFilter Field:=1, Criteria1:=.Range("H2").Value
    End With
End Sub
 
Upvote 0
how about declaring a Long variable like lastRow?

VBA Code:
Sub hi()
Dim lastRow As Long
    With Sheets("Rates")
        lastRow = .Cells(.Rows.Count, "L").End(xlUp).Row
        .Range("A1:L" & lastRow).AutoFilter Field:=2, Criteria1:=.Range("N24").Value
    End With
    With Sheets("Prom Codes")
        lastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
        .Range("A1:E" & lastRow).AutoFilter Field:=1, Criteria1:=.Range("H2").Value
    End With
End Sub

Thank you so much for your help!!!

Good News & Not So Good News
1st your code does work (ie it doesn't break my form), sadly I can barely even tell a difference in speed, but it might have sped up a little bit. Any other Ideas? I am here for the next 5 hours lol....

I really wish the people who built the table didn't add so many duplicates.... I checked in a seperate file over 9000 rows of duplicated items... But no.... they don't want me to change that.... lol
 
Upvote 0
Can you tell me what your code is doing?
 
Upvote 0
Can you tell me what your code is doing?

It uses a combobox drop down to allow me to search list, and then it puts combobox value into excel sheet which then filters appropriate column (long range), I then do the same for the rest of the items.

However all the boxes that deal with the long range has this issue. So the hope will be once 1 is fixed I'll just replicate it on the others.

The trick is getting each 1 to remember the filter done before it so that you end up with the shortest results as possible. Course since they duplicate...triplicated things spent 2 hours last night finding a way to just pull the first 3 rows found into userform!! With great help from this site!!

Image provided shows the form in action, and how they excel sheet looks after auto filter occurs.

Thanks!!!
 

Attachments

  • Form & Code 4 (Working).png
    Form & Code 4 (Working).png
    71.5 KB · Views: 4
Upvote 0
Can you tell me what your code is doing?

Fixed it, took out the auto filter and put that on its on on exit!!! So first part runs smoothly, 2nd part runs fine as well!!!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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