Ich möchte das VBA den Wert in G8 der Tabelle TPTagNr mit der Spalte B in der Tabelle TagListe überprüft
Falls der wert vorhanden ist soll es eine Meldung geben das der Wert vorhanden ist und das sub beendet wir.
Falls der wert nicht vorhanden soll es diesen in die nächste frei Zelle schreiben in der Spalte B in der Tabelle TagListe
Gruess und Danke
Private Sub CommandButton1_Click()
Dim lloRow As Long, lboExist As Boolean, lloLast As Long
If Range("G8").Value <> "" Then GoTo Line0 Else GoTo Line3:
Line0:
With Sheets("TagListe")
lloLast = .Cells(Rows.Count, 1).End(xlUp).Row
For lloRow = 2 To lloLast
If LCase(Range("G8").Value) = LCase(.Range("B" & lloRow).Value) Then GoTo Line1 Else GoTo Line2
lboExist = True
Exit For
Next
If lboExist = False Then GoTo Line2
Line2:
Application.EnableEvents = True 'Neu Reingeschrieben
Dim PNr As Integer
Dim SourceSheet As Worksheet
Dim TestStr As String
Startzeile = 3 ' erste Datenzeile
ActiveSheet.Unprotect
ActiveSheet.Unprotect
SourceCount = Startzeile
PNr = 0
Set SourceSheet = Application.Sheets("TagListe") ' suche in TagListe
While SourceSheet.Cells(SourceCount, 1).Value <> ""
If SourceSheet.Cells(SourceCount, 1).Value > PNr Then
PNr = SourceSheet.Cells(SourceCount, 1).Value
End If
SourceCount = SourceCount + 1
Wend
SourceCount = Startzeile
Tag = ThisWorkbook.Worksheets("TPTagNr").Range("G8").Value
Set SourceSheet = Application.Sheets("TagListe")
While SourceSheet.Cells(SourceCount, 1).Value <> ""
If SourceSheet.Cells(SourceCount, 1).Value > Tag Then
Tag = SourceSheet.Cells(SourceCount, 1).Value
End If
SourceCount = SourceCount + 1
Wend
SourceSheet.Cells(SourceCount, 1).Value = PNr + 1 ' neue Nummer eintragen
SourceSheet.Cells(SourceCount, 2).Value = Tag ' TagNummer eintragen
SourceSheet.Cells(SourceCount, 3).Value = Date + Time
GoTo Line3
Line1:
If ActiveWorkbook.Sheets("TagListe").Range("E2").Value <> 0 Then
MsgBox "Diesen Eintrag gibt es schon.", vbExclamation, "Hinweis"
lboExist = True
End If
Line3:
End With
End Sub
|