Mit dem nachfolgendem Code in einer UF möchte ich in der Arbeitsmappe A eine Suche in der arbeitsmappe B starten und alle gefunden Teilwerte in der cboliste1 auflisten lassen.
Ich bekomme jedoch die Fehlermeldung "Eigenschaft Listindex konnte nicht gesetzt werden".
Wo habe ich hier bitte den Fehler gemacht.
Private Sub CommandButtonSuche_Click()
Dim strCheck As String
Dim intI As Integer
Dim intJ As Integer
Dim intCount As Integer
Dim varCheck As Variant
Dim wks As Worksheet
Set wks = Workbooks("Masterfile.xls").Worksheets("Tabelle1")
With frmSuchen
.CommandButtonNext.Enabled = False
.CommandButtonPrevious.Enabled = False
.Repaint
End With
' Type 2 laesst Zahlen und Strings zu.
'strSuche = CStr(Application.InputBox(prompt:="Suche Eintrag...", Type:=2))
varCheck = CStr(Application.InputBox(prompt:="Suche Eintrag...", Type:=2))
'If Len(strSuche) = 0 Then
'If varCheck Then
If Len(varCheck) > 0 And varCheck "Falsch" Then
strSuche = CStr(varCheck)
Else
MsgBox "Kein Suchwert eingegeben", vbExclamation
Exit Sub
End If
intJ = frmSuchen.cboListe1.ListCount
intCount = 0
ReDim strFound(0)
For intI = 0 To intJ - 1
With frmSuchen
cboListe1.ListIndex = intI
strCheck = cboListe1.Value
If InStr(1, LCase(strCheck), LCase(strSuche)) > 0 Then
ReDim Preserve strFound(intCount)
strFound(intCount) = strCheck
intCount = intCount + 1
End If
End With
Next intI
If intCount = 0 Then
frmSuchen.cboListe1.ListIndex = 0
MsgBox "Kein passender Eintrag gefunden", vbExclamation
Exit Sub
End If
If UBound(strFound()) >= 0 Then
With frmSuchen
.CommandButtonNext.Enabled = True
.CommandButtonPrevious.Enabled = False
.cboListe1.Value = strFound(0)
End With
End If
intSelected = 0
End Sub
Private Sub CommandButtonNext_Click()
Dim intNosFound As Integer
intNosFound = UBound(strFound())
strSelected = frmSuchen.cboListe1.Value
If intSelected = intNosFound Then
frmSuchen.CommandButtonNext.Enabled = False
frmSuchen.CommandButtonPrevious.SetFocus
End If
End Sub
Private Sub CommandButtonPrevious_Click()
Dim intNosFound As Integer
intNosFound = UBound(strFound())
strSelected = frmSuchen.cboListe1.Value
If intSelected > 0 Then
Do While strSelected = strFound(intSelected)
intSelected = intSelected - 1
Loop
With frmSuchen
cboListe1.Value = strFound(intSelected)
End With
End If
frmSuchen.CommandButtonNext.Enabled = True
If intSelected
Danke
josef