Userform slow to open

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Evening,

I have a button which when pressed just opens a userform.

I press the button & straight away i see the outer border etc of the userform quite some seconds etc before the button,form color etc etc is even shown.
Im not sure what code you need to look at so i have supplied some below if you could advise please.

Code:
Private Sub UserForm_Initialize()'Modified  10/3/2018  5:51:42 AM  EDT
Application.ScreenUpdating = False
Dim LastRow As Long
LastRow = Sheets("POSTAGE").Cells(Rows.Count, "B").End(xlUp).Row
Dim Lastrowa As Long
Sheets("POSTAGE").Cells(8, 2).Resize(LastRow - 7).Copy Sheets("POSTAGE").Cells(1, 12)
Lastrowa = Sheets("POSTAGE").Cells(Rows.Count, "L").End(xlUp).Row
Sheets("POSTAGE").Cells(1, 12).Resize(Lastrowa).Sort key1:=Cells(1, 12).Resize(Lastrowa), order1:=xlAscending, Header:=xlNo
CustomerSearchBox.List = Sheets("POSTAGE").Cells(1, 12).Resize(Lastrowa).Value
ListBox1.List = Sheets("POSTAGE").Cells(1, 12).Resize(Lastrowa).Value
Sheets("POSTAGE").Cells(1, 12).Resize(Lastrowa).Clear
Application.ScreenUpdating = True
'USERNAME COMBOBOX


TextBox1.Value = Format(CDbl(Date), "dd/mm/yyyy")
TextBox2.SetFocus
End Sub

Code:
Private Sub UserForm_Activate()        'Dantes code
    'ListBox1.RowSource = "B:B" & Range("B" & Rows.Count).End(xlUp).Row
    Dim i As Long, j As Long, ws As Worksheet
    Set ws = Sheets("POSTAGE")
    For i = 8 To ws.Range("B" & Rows.Count).End(xlUp).Row
        added = False
        For j = 0 To ListBox1.ListCount - 1
            Select Case StrComp(ListBox1.List(j), ws.Cells(i, "B").Value, vbTextCompare)
                Case 0: added = True: Exit For
                Case 1: added = True: ListBox1.AddItem ws.Cells(i, "B").Value, j
                Exit For
            End Select
        Next
        If added = False Then ListBox1.AddItem ws.Cells(i, "B").Value
    Next
End Sub

Code:
 
Doesn't this line in UserForm_Initialize already do that ?
Code:
ListBox1.List = Sheets("POSTAGE").Cells(1, 12).Resize(Lastrowa).Value
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Doesn't this line in UserForm_Initialize already do that ?
Code:
ListBox1.List = Sheets("POSTAGE").Cells(1, 12).Resize(Lastrowa).Value

Follow up to my last message.
My worksheet is sorted by date in column A
This means column B where the names are shown are in no order.

What i then see now in the multiple code is that it gets the names from column B but as the sheet is date sorted it just shows the list as what my sheet shows.
If i sort my sheet by the names in column B then the listbox would be correct.

So this i think from memory is why i put that line of code in the initialize section as it takes column B sorts A-Z then the listbox1 is correct.

Did i explain that better for you.
 
Upvote 0
Doesn't matter how your sheet is sorted.

In UserForm_Initialize, customer names in column B are copied to column L,
sorted A-Z and loaded into both CustomerSearchBox.List and ListBox1.List.

UserForm_Activate not needed.
 
Upvote 0
Many thanks for the continued follow up with this.
Ive deleted it and opens as it should.
Dont know why I didn't try that but thanks.
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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