Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1472to1476
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Suchmakro auf mehrere Tabellenblätter erweitern

Suchmakro auf mehrere Tabellenblätter erweitern
04.02.2016 13:48:44
otto
Hallo zusammen,
mit folgenden Code durchsuche ich das aktuelle Tabellenblatt (nach Inhalt Spalte AA):
Private Sub TextBox1_Change()
Dim arr() As Variant, tmp As Variant, wks As Worksheet, wks1 As Worksheet, bolmatch
Dim index As Integer, intindex1
Dim x, icount, wert As Currency
ListBox1.Clear
awks = ActiveSheet.Name
Set wks = Sheets(awks)
x = wks.Range("A65536").End(xlUp).Row
tmp = wks.Range("AA8:AA" & x)
If TextBox1 = "" Then
ListBox1.Clear
Else
For index = 1 To UBound(tmp, 1)
bolmatch = InStr(1, tmp(index, 1), TextBox1, vbTextCompare) > 0
If bolmatch Then
ReDim Preserve arr(0 To 5, 0 To icount)
arr(0, icount) = wks.Cells(index + 7, 1)
arr(1, icount) = wks.Cells(index + 7, 2)
arr(2, icount) = wks.Cells(index + 7, 3)
arr(3, icount) = wks.Cells(index + 7, 24)
arr(4, icount) = VBA.Format(wks.Cells(index + 7, 30), "0.00")
arr(5, icount) = index + 7
icount = icount + 1
End If
Next
End If
If icount  0 Then
ListBox1.Column = arr
Else
ListBox1.Clear
End If
wert = 0
For intindex1 = 0 To ListBox1.ListCount - 1
wert = wert + ListBox1.List(intindex1, 4)
Next intindex1
Label13 = VBA.Format(wert, "0.00") & " €"
End Sub

Momentan ist das aktuelle Blatt "Februar".
Wie kann ich nun erreichen dass bei Bedarf (z.B. bei anhaken einer Checkbox), weitere Tabellenblätter durchsucht werden? (Januar - Dezember).
Danke für eure Mühen.
Möchte ungern was hochladen - sensible Daten!!
otto

2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Suchmakro auf mehrere Tabellenblätter erweitern
04.02.2016 14:12:28
Max
ungeprüft...

Private Sub TextBox1_Change()
Dim arr() As Variant, tmp As Variant, wks As Worksheet, wks1 As Worksheet, bolmatch
Dim index As Integer, intindex1
Dim x, icount, wert As Currency
ListBox1.Clear
For Each wks In ThisWorkbook.Worksheets
x = wks.Range("A65536").End(xlUp).Row
tmp = wks.Range("AA8:AA" & x)
If TextBox1 = "" Then
ListBox1.Clear
Else
For index = 1 To UBound(tmp, 1)
bolmatch = InStr(1, tmp(index, 1), TextBox1, vbTextCompare) > 0
If bolmatch Then
ReDim Preserve arr(0 To 5, 0 To icount)
arr(0, icount) = wks.Cells(index + 7, 1)
arr(1, icount) = wks.Cells(index + 7, 2)
arr(2, icount) = wks.Cells(index + 7, 3)
arr(3, icount) = wks.Cells(index + 7, 24)
arr(4, icount) = VBA.Format(wks.Cells(index + 7, 30), "0.00")
arr(5, icount) = index + 7
icount = icount + 1
End If
Next
End If
Next ' ******
If icount  0 Then
ListBox1.Column = arr
Else
ListBox1.Clear
End If
wert = 0
For intindex1 = 0 To ListBox1.ListCount - 1
wert = wert + ListBox1.List(intindex1, 4)
Next intindex1
Label13 = VBA.Format(wert, "0.00") & " €"
End Sub
Gruß UweD

Anzeige
AW: Suchmakro auf mehrere Tabellenblätter erweitern
05.02.2016 06:53:31
otto
Hi,
danke erstmal, ganz so ging es nicht, habe es ein wenig umgeschrieben. Nun mit Checkbox zur optionales Suche in allen TB.
So läuft es.
Private Sub TextBox1_Change()
Dim arr() As Variant, tmp As Variant, wks As Worksheet, ws As Worksheet, bolmatch
Dim index As Integer, intindex1
Dim x, icount, wert As Currency
ListBox1.Clear
wert = 0
If CheckBox1 = False Then GoTo monat
For Each wks In ActiveWorkbook.Worksheets
monat:
If CheckBox1 = False Then
x = Range("A65536").End(xlUp).Row
tmp = Range("AA8:AA" & x)
Else
x = Sheets(wks.Name).Range("A65536").End(xlUp).Row
tmp = Sheets(wks.Name).Range("AA8:AA" & x)
End If
If TextBox1 = "" Then
ListBox1.Clear
Else
For index = 1 To UBound(tmp, 1)
bolmatch = InStr(1, tmp(index, 1), TextBox1, vbTextCompare) > 0
If bolmatch Then
ReDim Preserve arr(0 To 5, 0 To icount)
If CheckBox1 = False Then
arr(0, icount) = Cells(index + 7, 1)
arr(1, icount) = Cells(index + 7, 2)
arr(2, icount) = Cells(index + 7, 3)
arr(3, icount) = Cells(index + 7, 24)
arr(4, icount) = VBA.Format(Cells(index + 7, 30), "0.00")
arr(5, icount) = index + 7
Else
arr(0, icount) = Sheets(wks.Name).Cells(index + 7, 1)
arr(1, icount) = Sheets(wks.Name).Cells(index + 7, 2)
arr(2, icount) = Sheets(wks.Name).Cells(index + 7, 3)
arr(3, icount) = Sheets(wks.Name).Cells(index + 7, 24)
arr(4, icount) = VBA.Format(Sheets(wks.Name).Cells(index + 7, 30), "0.00")
arr(5, icount) = Sheets(wks.Name).Rows(index + 7)
End If
icount = icount + 1
End If
Next
End If
If CheckBox1 = False Then GoTo weiter
Next wks
weiter:
If icount  0 Then
ListBox1.Column = arr
Else
ListBox1.Clear
End If
For intindex1 = 0 To ListBox1.ListCount - 1
wert = wert + ListBox1.List(intindex1, 4)
Next intindex1
Label13 = VBA.Format(wert, "0.00") & " €"
If CheckBox1 = False Then
Label14 = "(" & VBA.Format(wert * 100 / Cells(2, 21), "0.0") & " %)"
Else
Label14 = "(" & VBA.Format(wert * 100 / Sheets("2016").Cells(38, 12), "0.0") & " %)"
End If
End Sub
Gruß otto
Anzeige

302 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige