VBA-Code beschleunigen
23.09.2018 22:41:41
Markus
besteht eine Möglichkeiten den unten angehängten Code etwas zu "beschleunigen". Dauert leider bei der Menge an Daten ungefähr 25 Sekunden bis die UserForm aufgeht, auf die sich der Code bezieht.
Private Sub ComboBox1_Change()
If Not Bypass Then
FillListbox 2, 1
End If
End Sub
Private Sub ComboBox2_Change()
If Not Bypass Then
FillListbox 2, 1
End If
End Sub
Private Sub ComboBox3_Change()
If Not Bypass Then
FillListbox 2, 1
End If
End Sub
Private Sub ComboBox4_Change()
If Not Bypass Then
FillListbox 2, 1
End If
End Sub
Private Sub ComboBox5_Change()
If Not Bypass Then
FillListbox 2, 1
End If
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
' Bypass...
Bypass = True
' Comboboxen füllen...
FillCombobox "ComboBox1", 2, 1
FillCombobox "ComboBox2", 2, 2
FillCombobox "ComboBox3", 2, 3
FillCombobox "ComboBox4", 2, 4
FillCombobox "ComboBox5", 2, 5
' Listbox Einstellungen...
ListBox1.ColumnCount = 5
' Listbox füllen...
FillListbox 2, 1
' Bypass...
Bypass = False
End Sub
Private Function FillCombobox(Control As String, Row As Long, Column As Long)
Dim n As Long
Dim t As String
Dim v As String
Dim c As Collection
Dim d() As String
' Fehler abschalten...
On Error Resume Next
' Collection erzeugen...
Set c = New Collection
' Clear...
Me.Controls(Control).Clear
' Alles...
Me.Controls(Control).AddItem "All"
' Tabelle1...
With ThisWorkbook.Worksheets("Tabelle1")
' Einlesen...
For n = 1 To 3000
v = ""
v = .Cells(n + Row - 1, Column).Value
t = ""
t = c("Key=" & v)
If Len(t)
Private Function FillListbox(Row As Long, Column As Long)
Dim b As Boolean
Dim n As Long
' Clear...
ListBox1.Clear
' Tabelle1...
With ThisWorkbook.Worksheets("Tabelle1")
' Einlesen...
For n = 1 To 3000
' Reset...
b = True
' Bedingungen...
If ComboBox1.ListIndex > 0 Then
b = b And Not CBool(CStr(.Cells(n + Row - 1, Column + 0).Value) _
(ComboBox1.List(ComboBox1.ListIndex, 0)))
End If
If ComboBox2.ListIndex > 0 Then
b = b And Not CBool(CStr(.Cells(n + Row - 1, Column + 1).Value) _
(ComboBox2.List(ComboBox2.ListIndex, 0)))
End If
If ComboBox3.ListIndex > 0 Then
b = b And Not CBool(CStr(.Cells(n + Row - 1, Column + 2).Value) _
(ComboBox3.List(ComboBox3.ListIndex, 0)))
End If
If ComboBox4.ListIndex > 0 Then
b = b And Not CBool(CStr(.Cells(n + Row - 1, Column + 3).Value) _
(ComboBox4.List(ComboBox4.ListIndex, 0)))
End If
If ComboBox5.ListIndex > 0 Then
b = b And Not CBool(CStr(.Cells(n + Row - 1, Column + 4).Value) _
(ComboBox5.List(ComboBox5.ListIndex, 0)))
End If
' Hinzufügen...
If b Then
ListBox1.AddItem
ListBox1.List(ListBox1.ListCount - 1, 0) = .Cells(n + Row - 1, Column + 0).Value
ListBox1.List(ListBox1.ListCount - 1, 1) = .Cells(n + Row - 1, Column + 1).Value
ListBox1.List(ListBox1.ListCount - 1, 2) = .Cells(n + Row - 1, Column + 2).Value
ListBox1.List(ListBox1.ListCount - 1, 3) = .Cells(n + Row - 1, Column + 3).Value
ListBox1.List(ListBox1.ListCount - 1, 4) = .Cells(n + Row - 1, Column + 4).Value
End If
Next
End With
' Index...
If ListBox1.ListCount > 0 Then
ListBox1.ListIndex = 0
End If
End Function
Vielen Dank euch!