AW: Variable Suche, Spalten über Userform de
07.11.2020 16:46:54
Nepumuk
Hallo Curly,
teste mal:
Option Explicit
Sub Search()
Dim c As Range
Dim lngZeile As Long
Dim rngBereich As Range
Dim lngAnzahl As Long
Dim strFirst As String
Dim arrStock As Variant
Dim i, ii, X As Byte
Dim iAnzahl As Integer
Redim vTemp(0 To 6, 0 To 100) As Variant
Dim iIndx As Integer
Dim AnzahlBetriebe As Integer
Dim iSuche As Integer
Dim lngIndex As Long
UserForm1.ListBox1.Clear
arrStock = Array("StockA", "StockB", "StockC")
For i = LBound(arrStock) To UBound(arrStock)
With Sheets(CStr(arrStock(i)))
Set rngBereich = Nothing
For lngIndex = 2 To 7
If Worksheets("Suche").Cells(lngIndex, 2).Value = "ja" Then
If rngBereich Is Nothing Then
Set rngBereich = .Columns(lngIndex - 1)
Else
Set rngBereich = Union(rngBereich, .Columns(lngIndex - 1))
End If
End If
Next lngIndex
Set c = rngBereich.Find(UserForm1.TextBox1.Text, LookIn:=xlValues, LookAt:=xlPart)
If Not c Is Nothing Then
strFirst = c.Address
Do
' If c.Row = lngZeile Then GoTo naechste
vTemp(0, iAnzahl) = arrStock(i)
For iIndx = 1 To 6
vTemp(iIndx, iAnzahl) = .Cells(c.Row, iIndx)
Next iIndx
iAnzahl = iAnzahl + 1
' lngZeile = c.Row
naechste:
Set c = rngBereich.FindNext(c)
Loop While Not c Is Nothing And c.Address <> strFirst
End If
End With
Next i
If iAnzahl = 0 Then
MsgBox "Es wurde keine Treffer gefunden!", vbInformation, "Hinweis"
GoTo ende
End If
Redim arrTemp(0 To 6, 0 To iAnzahl - 1)
Redim Preserve vTemp(0 To 6, 0 To iAnzahl - 1)
If (iAnzahl - 1) = 0 Then
Redim arrTemp(1 To 1, 0 To 6)
For i = 0 To 6
arrTemp(1, i) = vTemp(i, 0)
Next i
Else
arrTemp = WorksheetFunction.Transpose(vTemp)
End If
UserForm1.ListBox1.List() = arrTemp
ende:
Erase vTemp
Erase arrTemp
End Sub
Gruß
Nepumuk