AW: Code umschreiben
15.05.2020 10:39:08
Gast1505
Ich muss mich entschuldigen aber ich verstehe gerade nur Bahnhof...
Ist es möglich die TextBox automatisch zu befüllen?
Ist .AddItem der falsche Ausdruck dafür?
Hier ist mein vollständiger Code
Private Sub CommandButton1_Click()
'Rückfrage wenn Textbox leer
If TextBox_Datum_E = "" Then
MsgBox ("Bitte Datum eintragen")
Exit Sub
End If
If TextBox_Zeit_E = "" Then
MsgBox ("Bitte Zeit eintragen")
Exit Sub
End If
If TextBox_Wächter_E = "" Then
MsgBox ("Bitte Kurzzeichen eintragen")
Exit Sub
End If
If TextBox_Name = "" Then
MsgBox ("Bitte Name vom Fahrer eintragen")
Exit Sub
End If
If TextBoxFirma = "" Then
MsgBox ("Bitte Firma eintragen")
Exit Sub
End If
If TextBox_KZ1 = "" Then
MsgBox ("Bitte Kontrollschild eintragen")
Exit Sub
End If
If TextBox_SB = "" Then
MsgBox ("Bitte Kontaktperson eintragen")
Exit Sub
End If
If TextBox_Material = "" Then
MsgBox ("Bitte eintragen was Geliefert wurde oder -")
Exit Sub
End If
'Erste Freie Zeile ausfindig machen
Application.EnableEvents = True
Application.ScreenUpdating = False
Worksheets("Auf Areal").Activate
Dim last As Integer
last = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row + 1
'Wächter Eintritt
Cells(last, 1).Value = TextBox_Wächter_E
'Datum Eintritt
Cells(last, 2).Value = TextBox_Datum_E
'Zeit Eintritt
Cells(last, 3).Value = TextBox_Zeit_E
'Name Fahrer
Cells(last, 4).Value = TextBox_Name
'Name Firma
Cells(last, 5).Value = TextBoxFirma
'Kontrollschild
Cells(last, 6).Value = TextBox_KZ1
'Kategorie
If OptionButton_LKW.Value = True Then Cells(last, 7).Value = "LKW"
If OptionButton_PKW.Value = True Then Cells(last, 7).Value = "PKW"
If OptionButton_Transporter.Value = True Then Cells(last, 7).Value = "Transporter"
If OptionButton_Andere.Value = True Then Cells(last, 7).Value = TextBox_Andere
'Sachbearbeiter
Cells(last, 8).Value = TextBox_SB
'Ware
Cells(last, 9).Value = TextBox_Material
'Abladeort
Cells(last, 10).Value = ListBox_Ladeort.Value
'Ware Beschädigt
If OptionButton_Nein.Value = True Then Cells(last, 11).Value = "Nein"
If OptionButton_Ja.Value = True Then Cells(last, 11).Value = "Ja"
Cells(last, 11).Value = TextBox_Ware_beschädigt
'Bemerkungen
Cells(last, 12).Value = TextBox_Bemerkung
'Gammaalarm
If OptionButton_Gamma_Nein.Value = True Then Cells(last, 13).Value = "Nein"
If OptionButton_Gamma_Ja.Value = True Then Cells(last, 13).Value = "Ja"
'Bemerkungen Gammaalarm
Cells(last, 15).Value = TextBox_Bemerkungen_Gamma
'Austritt Wächter
Cells(last, 16).Value = TextBox_Wächter_A
'Austritt Datum
Cells(last, 17).Value = TextBox_Datum_A
'Austritt Zeit
Cells(last, 17).Value = TextBox_Zeit_A
'Liste leeren
TextBox_Wächter_E = ""
TextBox_Name = ""
TextBoxFirma = ""
TextBox_KZ1 = ""
TextBox_SB = ""
TextBox_Material = ""
TextBox_Bemerkung = ""
TextBox_Bemerkungen_Gamma = ""
TextBox_Wächter_A = ""
TextBox_Datum_A = ""
TextBox_Zeit_A = ""
End Sub
Private Sub CommandButton2_Click()
Sheets("Auf Areal").Select
Unload UserForm3
Unload UserForm1
End Sub
Private Sub TextBox_KZ1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim rngFind As Range
Dim rngFirst As Range
Set rngFind = Sheets("Erfassen").UsedRange.Find( _
what:=TextBox_KZ1.Text, _
lookat:=xlPart, _
LookIn:=xlValues)
If rngFind Is Nothing Then
' Beep
MsgBox "Keine Gesuch gefunden!"
Exit Sub
End If
Set rngFirst = rngFind
Do
TextBox_SB.AddItem
TextBoxFirma.AddItem
TextBoxFirma = TextBoxFirma & rngFind.Value
TextBox_SB = TextBox_SB& rngFind.Row
Set rngFind = Sheets("Erfassen").UsedRange.FindNext(rngFind)
Loop While Not rngFind Is Nothing And _
rngFind.Address rngFirst.Address
End Sub
Private Sub TextBox_Datum_A_Enter()
TextBox_Datum_A.Value = Date
End Sub
Private Sub TextBox_Wächter_A_Enter()
TextBox_Wächter_A.Value = Application.UserName
End Sub
Private Sub TextBox_Wächter_E_Enter()
TextBox_Wächter_E.Value = Application.UserName
End Sub
Private Sub TextBox_Zeit_A_Enter()
TextBox_Zeit_A.Value = Time
End Sub
Private Sub UserForm_Initialize()
TextBox_Datum_E = Date
TextBox_Zeit_E = Time
'TextBox_Ware_beschädigt = "Wenn Ja ausfüllen"
'TextBox_Bemerkungen_Gamma = "Alarm beschreiben"
'TextBox_SU_MA = "Bei Alarm Ausfüllen"
OptionButton_Nein.Value = True 'Ware Beschädigt Standart Nein
OptionButton_Gamma_Nein.Value = True ' Gammaalarm Standart Nein
'Ab-/Aufladeort
With ListBox_Ladeort
.AddItem "Areal"
.AddItem "Vor der Schleuse"
.AddItem "In der Schleuse"
.AddItem "Revisions Parkplatz"
.AddItem "Kein Material"
End With
ThisWorkbook.Save
End Sub
Hoffe du kannst mir jetzt besser Auskunft geben