Zellen vergleichen / Spalten vergleichen
16.08.2003 08:23:38
Erich M.
hallo Klaus-Dieter,
ich bastle immer noch an einem Spalten-Vergleich. Bei nachstehendem Code (wird in einer UserForm eingesetzt; der Code stammt z.T. von Klaus-Dieter) habe ich nun festgestellt, dass beim Vergleich von Zellen, nicht die vollständige Zelle verglichen wird, sondern immer die ersten Zeichen.
Das bedeutet, wenn "Hub" mit "Huber" verglichen wird, wird es als identisch erkannt.
Kann man das ändern?
Private Sub CommandButton3_Click()
Dim zelle As Range, Tb(1 To 15) As Worksheet, gefunden As Boolean, zeile As Long
If ComboBox1.Text = "" Then MsgBox "Bitte Datei 1 auswählen.", 48, "Hinweis": Exit Sub
If ComboBox11.Text = "" Then MsgBox "Bitte Datei 2 auswählen.", 48, "Hinweis": Exit Sub
If ComboBox2.Text <> "" Then Set Tb(1) = Workbooks(ComboBox1.Text).Worksheets(ComboBox2.Text) Else MsgBox "Bitte Tabellenblatt 1 auswählen.", 48, "Hinweis": Exit Sub
If ComboBox12.Text <> "" Then Set Tb(2) = Workbooks(ComboBox11.Text).Worksheets(ComboBox12.Text) Else MsgBox "Bitte Tabellenblatt 2 auswählen.", 48, "Hinweis": Exit Sub
If ComboBox3 = "" Then MsgBox "Bitte Vergleichsspalte 1 auswählen.", 48, "Hinweis": Exit Sub
If ComboBox13 = "" Then MsgBox "Bitte Vergleichsspalte 2 auswählen.", 48, "Hinweis": Exit Sub
For Each Tb(3) In ThisWorkbook.Worksheets
If Tb(3).Name = "Fehlende" Then gefunden = True: Exit For
Next
If Not gefunden Then
Worksheets.Add.Move after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "Fehlende"
End If
Set Tb(3) = ThisWorkbook.Worksheets("Fehlende")
With Tb(3)
.Cells.Clear
.Cells(1, 1) = "Es fehlen in"
.Cells(1, 2) = "Es fehlen in"
.Cells(2, 3) = "Datei"
.Cells(3, 3) = "Tabelle"
.Cells(4, 3) = "Spalte"
.Cells(5, 1) = "'"
.Cells(5, 2) = "'"
' .Cells(5, 1) = "Nachstehende Zeilen wurden aus der Tabelle " & myName1 & " kopiert"
.Cells(2, 1) = ComboBox1
.Cells(3, 1) = ComboBox2
.Cells(4, 1) = ComboBox3
.Cells(2, 2) = ComboBox11
.Cells(3, 2) = ComboBox12
.Cells(4, 2) = ComboBox13
End With
With Tb(1)
For zeile = 1 To Tb(1).Cells(65536, CInt(ComboBox3.Text)).End(xlUp).Row
If .Cells(zeile, CInt(ComboBox3.Text)) <> "" Then
Set zelle = Tb(2).Range(Tb(2).Cells(1, CInt(ComboBox13.Text)), Tb(2).Cells(Tb(2).Cells(65536, CInt(ComboBox13.Text)).End(xlUp).Row, CInt(ComboBox13.Text))).Find(.Cells(zeile, CInt(ComboBox3.Text)))
If zelle Is Nothing Then Tb(3).Cells(Tb(3).Cells(65536, 2).End(xlUp).Row + 1, 2) = .Cells(zeile, CInt(ComboBox3.Text))
End If
Next
End With
With Tb(2)
For zeile = 1 To Tb(2).Cells(65536, CInt(ComboBox13.Text)).End(xlUp).Row
If .Cells(zeile, CInt(ComboBox13.Text)) <> "" Then
Set zelle = Tb(1).Range(Tb(1).Cells(1, CInt(ComboBox3.Text)), Tb(1).Cells(Tb(1).Cells(65536, CInt(ComboBox3.Text)).End(xlUp).Row, CInt(ComboBox3.Text))).Find(.Cells(zeile, CInt(ComboBox13.Text)))
If zelle Is Nothing Then Tb(3).Cells(Tb(3).Cells(65536, 1).End(xlUp).Row + 1, 1) = .Cells(zeile, CInt(ComboBox13.Text))
End If
Next
End With
Unload Me
ThisWorkbook.Activate
Worksheets("Fehlende").Select
ActiveWindow.FreezePanes = False
Range("B6").Select
ActiveWindow.FreezePanes = True
Columns("A:C").EntireColumn.AutoFit
Range("A1:C4").Select
With Selection
.HorizontalAlignment = xlCenter
End With
Range("A4:I4").Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = 3 'xlAutomatic
End With
Range("5:5").Select
Selection.RowHeight = 6
Range("C1").Select
End Sub
Code eingefügt mit: Excel Code Jeanie
Kann man das ändern?
mfg
Erich