Excel VBA Suche - Typen Unverträglich
20.06.2022 17:04:03
Gerwin
bislang konnte ich dank des tollen Forums meine Probleme immer durch vorhandene Beiträge lösen, gegenwärtig weiß ich jedoch nicht mehr weiter.
Diese Frage baut auf dem tollen Code von Rudi auf, den ich im Archiv gefunden habe. https://www.herber.de/forum/archiv/1364to1368/1367192_Effiziente_Suchfunktion_fuer_Datenbank.html
Mein Problem ist gegenwärtig, dass egal wie ich es anstelle eine Fehlermeldung "Typen Unverträglich" für die Zeile
j = LBound(arrTmp, 2)
bekomme.Wenn ich den Code in einer Blankoarbeitsmappe ausprobiere, läuft er. Bei mir jedoch nicht. Jeglicher Schutz ist deaktiviert und auch alle Events habe ich ausgeschaltet zum testen, aber auch nix.
Weiß hier jemand rat?
Viele Grüße
Gerwin
Option Explicit
Dim arrWerte, bolCode As Boolean, sLast
Private Sub Suchfenster_Initialize()
sLast = txtSuche
arrWerte = DasArray
txtSuche = ""
End Sub
Private Sub lbxFund_Click()
Dim Tabellenblatt As Worksheet
If Not bolCode Then
With lbxFund
On Error GoTo Errorhandler
Application.ScreenUpdating = False
Call AUFBlenden
Call S_AUS_DB
Sheets("DATENBANK").Range("B1").Value = "$B$7"
Call S_AN_DB
Sheets("ZELT 1").Visible = True
Sheets("ZELT 2").Visible = True
Sheets("ZELT 3").Visible = True
Sheets("CONTAINER").Visible = True
Application.ScreenUpdating = True
Worksheets(.Column(0)).Activate
Range(.Column(1)).Select
For Each Tabellenblatt In ThisWorkbook.Worksheets
If Tabellenblatt.Name ThisWorkbook.ActiveSheet.Name Then
Tabellenblatt.Visible = xlSheetHidden
End If
Next Tabellenblatt
End With
lbxFund.ListIndex = -1
Hide
End If
Application.EnableEvents = True
Exit Sub
Errorhandler:
Application.EnableEvents = True
Call AUFBlenden_AUS
MsgBox "Kein Gültiger Datensatz ausgewählt", vbCritical, "Fehler"
Exit Sub
End Sub
Private Sub txtSuche_Change()
'Application.EnableEvents = False
Dim i As Long, j As Integer, oTmp As Object, arrList, oT, n As Long, arrTmp
bolCode = True
If txtSuche = "" Then
lbxFund.Clear
sLast = ""
'Application.EnableEvents = True
Exit Sub
End If
If sLast "" Then
If txtSuche Like sLast & "*" Then
arrTmp = lbxFund.List
Else
arrTmp = arrWerte
End If
Else
arrTmp = arrWerte
End If
Set oTmp = CreateObject("Scripting.dictionary")
j = LBound(arrTmp, 2)
For i = LBound(arrTmp) To UBound(arrTmp)
If LCase(arrTmp(i, j + 2)) Like "*" & LCase(txtSuche) & "*" Then
oTmp(i) = Array(arrTmp(i, j), arrTmp(i, j + 1), arrTmp(i, j + 2))
End If
Next
If oTmp.Count Then
ReDim arrList(1 To oTmp.Count, 1 To 3)
For Each oT In oTmp
n = n + 1
arrList(n, 1) = oTmp(oT)(0)
arrList(n, 2) = oTmp(oT)(1)
arrList(n, 3) = oTmp(oT)(2)
Next
lbxFund.List = arrList
sLast = txtSuche
Else
lbxFund.Clear
sLast = ""
End If
bolCode = False
Application.EnableEvents = True
End Sub
Private Function DasArray()
Application.EnableEvents = False
Dim oCells As Object, wks As Worksheet, rngC As Range
Dim oKey, arrTmp, n As Long
Set oCells = CreateObject("Scripting.dictionary")
For Each wks In Worksheets
For Each rngC In wks.UsedRange.Cells
If rngC "" Then
oCells(rngC) = rngC.Value
End If
Next
Next
ReDim arrTmp(1 To oCells.Count, 1 To 3)
For Each oKey In oCells
n = n + 1
arrTmp(n, 1) = oKey.Parent.Name
arrTmp(n, 2) = oKey.Address
arrTmp(n, 3) = oCells(oKey)
Next
DasArray = arrTmp
Application.EnableEvents = True
End Function