AW: Zelleninhalt mit textbox vergleichen
21.09.2014 01:30:17
Mullit
Hallo,
weiß jetzt nicht was Du genau willst(vermutlich eine Schleife) also mal 3 Möglichkeiten:
Für eine einzelne ausgewählte Zelle:
Option Explicit
Private Sub CommandButton1_Click()
If ActiveCell = TextBox1 Then
ActiveCell.Offset(0, 1) = "ok"
End If
End Sub
Für einen ausgewählten Bereich:
Option Explicit
Private Sub CommandButton1_Click()
Dim objCell As Range
For Each objCell In Selection
If objCell = TextBox1 Then
objCell.Offset(0, 1) = "ok"
End If
Next
End Sub
Für alle Daten in Spalte 1:
Option Explicit
Private Sub CommandButton1_Click()
Dim objCell As Range
For Each objCell In Cells(1, 1).Resize(Cells(Rows.Count, 1).End(xlUp).Row, 1)
If objCell = TextBox1 Then
objCell.Offset(0, 1) = "ok"
End If
Next
End Sub
Und noch eine Array-Variante:
Option Explicit
Private Sub CommandButton1_Click()
Dim avntArray As Variant
Dim ialngIndex As Long
avntArray = Cells(1, 1).Resize(Cells(Rows.Count, 1).End(xlUp).Row, 1)
For ialngIndex = 1 To UBound(avntArray)
If avntArray(ialngIndex, 1) = TextBox1 Then
avntArray(ialngIndex, 1) = "ok"
Else
avntArray(ialngIndex, 1) = vbNullString
End If
Next
Cells(1, 2).Resize(Cells(Rows.Count, 1).End(xlUp).Row, 1) = avntArray
End Sub
Gruß,