AW: Werte, die in liste 2 mal vorkommen ausblenden!
10.11.2008 15:58:00
Tino
Hallo,
habe mal einige Kommentare in den Code geschrieben,
damit sollte es besser nachvollziehbar sein.
Option Explicit
Private Sub ListBox1_GotFocus()
Dim Cell As Range
Dim tempVar()
Dim lngInt As Long, i As Long
'Anzahl für größe der Area bestimmen
lngInt = Worksheets("Philips (A)").Range("SupplierAs").Cells.Count
lngInt = lngInt + Worksheets("Philips (EU)").Range("SupplierEU").Cells.Count
lngInt = lngInt + Worksheets("Philips (US)").Range("SupplierUS").Cells.Count
'Area Dimensionieren
Redim tempVar(1 To lngInt, 0)
'Index für Area auf eins setzen
i = 1
With Me.ListBox1
'Listbox leeren
.Clear
'Schleife über ersten Zellbereich
For Each Cell In Worksheets("Philips (A)").Range("SupplierAs")
'prüfen ob Zelle leer ist
If Cell <> "" Then
'Application.Match(Cell, tempVar, 0)
'wird der Wert in der Area gefunden,
'gibt diese Funktion einen numerischen Wert zurück,
'sonst einen Fehlerwert und dieser wäre somit nicht numerisch,
'Die 0 besagt, dass nach einer genauen Übereinstimmung gesucht werden soll
'siehe auch in Excel Hilfe unter der Funktion Vergleich
If IsNumeric(Application.Match(Cell, tempVar, 0)) = False Then
'ist Wert nicht numerisch, ist der Wert noch nicht in der Area
'und wird somit in die Area aufgenommen
tempVar(i, 0) = Cell
'Wert in die Listbox aufnehmen
.AddItem Cell.Value
'Index für Area um eins erhöhen
i = i + 1
End If
End If
Next
For Each Cell In Worksheets("Philips (EU)").Range("SupplierEU")
If Cell <> "" Then
If IsNumeric(Application.Match(Cell, tempVar, 0)) = False Then
tempVar(i, 0) = Cell
.AddItem Cell.Value
i = i + 1
End If
End If
Next
For Each Cell In Worksheets("Philips (US)").Range("SupplierUS")
If Cell <> "" Then
If IsNumeric(Application.Match(Cell, tempVar, 0)) = False Then
tempVar(i, 0) = Cell
.AddItem Cell.Value
i = i + 1
End If
End If
Next
End With
End Sub
Viel Spaß beim testen.
Gruß Tino
www.VBA-Excel.de