AW: VBA Problem
29.05.2017 17:57:39
Piet
Hallo Peter
ich habe ein Weile gebraucht den Fehler zu verstehen, jetzt sollte er beseitigt sein.
Den unteren Code Teil bitte auswechseln, dann sollte es funktionieren.
mfg Piet
Dim last As Integer, ok As Variant
Dim Eingabe As String 'Flag für ComboBox
Private Sub ComboBox1_Change()
Dim last As Integer
With Worksheets("Artikel")
'Kein neu laden beim Bearbeiten !!
If Eingabe = "Ja" Then Exit Sub
last = ComboBox1.ListIndex + 2
TextBoxArtikel1.Value = .Cells(last, 1).Value
TextBoxArtikelnummer2.Value = .Cells(last, 2).Value
TextBoxPreis3.Value = .Cells(last, 3).Value
TextBoxEinheit4.Value = .Cells(last, 4).Value
End With
End Sub
Private Sub CommandButtonBearbeiten2_Click()
With Worksheets("Artikel")
On Error GoTo Fehler
Eingabe = "Ja" 'Flag für: No ComboBox_Change
Application.EnableEvents = False
last = frmEingabe.ComboBox1.ListIndex + 2
'Warnung wenn Artikel Nummer überschrieben wird !!
If Cells(last, 2).Value TextBoxArtikelnummer2.Text Then
ok = MsgBox("Warnung - Die Artikel Nummer wird überschrieben" & Chr(10) & "Ist das Okay ? _
", vbOKCancel)
If ok = vbCancel Then TextBoxArtikelnummer2.Text = Cells(last, 2).Value: Exit Sub
'Warnung wenn Artikel Bezeichnung überschrieben wird !!
ElseIf Cells(last, 1).Value TextBoxArtikel1.Text Then
ok = MsgBox("Warnung - Die Artikel Bezeichnung wird überschrieben" & Chr(10) & "Ist das _
Okay ?", vbOKCancel)
If ok = vbCancel Then TextBoxArtikel1.Text = Cells(last, 1).Value: Exit Sub
'Warnung wenn Einheit kg überschrieben wird !!
ElseIf Cells(last, 4).Value TextBoxEinheit4.Text Then
ok = MsgBox("Warnung - Die Einheit kg/DS wird überschrieben" & Chr(10) & "Ist das Okay ?" _
, vbOKCancel)
If ok = vbCancel Then TextBoxEinheit4.Text = Cells(last, 4).Value: Exit Sub
'Warnung wenn Preis in EU überschrieben wird !!
ElseIf Cells(last, 3).Value TextBoxPreis3.Text Then
ok = MsgBox("Warnung - Die Preis in EU wird überschrieben" & Chr(10) & "Ist das Okay ?", _
vbOKCancel)
If ok = vbCancel Then TextBoxPreis3.Text = Cells(last, 3).Value: Exit Sub
End If
'Eingabe in aktive Zeile schreiben
Cells(last, 1).Value = TextBoxArtikel1.Text
Cells(last, 2).Value = TextBoxArtikelnummer2.Text
Cells(last, 3).Value = CCur(TextBoxPreis3)
Cells(last, 4).Value = TextBoxEinheit4.Text
Fehler: Eingabe = Empty
'im Fehlerfall immer auf True
Application.EnableEvents = True
End With
End Sub