gebastelt
24.06.2014 16:24:32
Rudi
Hallo,
funktioniert mit 170 Tabellen und ca. 85.000 Zellinhalten ganz gut. Nur der erste Aufruf dauert ca 4 Sek.
UF mit TextBox txtSuche und ListBox lbxFund.
In der UF:
Option Explicit
Dim arrWerte, bolCode As Boolean, sLast
Private Sub UserForm_Initialize()
sLast = txtSuche
arrWerte = DasArray
End Sub
Private Sub lbxFund_Click()
If Not bolCode Then
With lbxFund
Worksheets(.Column(0)).Activate
Range(.Column(1)).Select
End With
lbxFund.ListIndex = -1
Hide
End If
End Sub
Private Sub txtSuche_Change()
Dim i As Long, j As Integer, oTmp As Object, arrList, oT, n As Long, arrTmp
bolCode = True
If txtSuche = "" Then
lbxFund.Clear
sLast = ""
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
End Sub
Private Function DasArray()
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
End Function
Und irgendwo ein Button zum Starten.
Gruß
Rudi