Live-Forum - Die aktuellen Beiträge
Datum
Titel
28.03.2024 21:12:36
28.03.2024 18:31:49
Anzeige
Archiv - Navigation
1612to1616
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Ja Nein Abfrage
14.03.2018 11:42:13
Andreas
Hallo Excelgemeinde,
Ich habe im Netz viele Hinweise gefunden, kann diese aber nicht umsetzen.
Mit folgendem Code trage ich per Commandbutton die Werte aus Combo- und Textboxen in ein Tabellenblatt.
Vor der Eintragung wird geprüft ob alle Pflichtboxen gefüllt sind bzw. 2 Textboxen den gleichen Wert haben.
Eine Kontrollabfrage fehlt mir noch, die ich nicht hinbekomme:
In der TextBoxB_ER muss in 99% aller Fälle ein Minusbetrag stehen. Deshalb möchte ich dort eine Sicherheitsabfrage einbauen.
Ist der Wert der TextboxB_ER positiv (null habe ich ja schon abgefragt) soll eine Ja Nein Msg erscheinen. Bei Ja sollen die Eintragungen vorgenommen werden. Bei nein sollen die Textboxen B_ER und 1 - 32 wieder auf 0,00 gestellt werden und der Fokus auf TextBoxleerER gesetzt werden.
Private Sub CommandButtonER_Click()
Dim lngZeile  As Long
lngZeile = Cells(5, 1).End(xlDown).Row + 1
' Abfrage ob Pflichtfelder gefüllt sind
If ComboBox_BuchungsortER.ListIndex = -1 Or ComboBox_BuchungsdatumER.ListIndex = -1 Or  _
TextBoxB_ER.Value = 0 Or ComboBox_DatenER.Text = "" Or ComboBox_VorgangER.Text = "" Then
MsgBox "Bitte alle Pflichtfelder * füllen!", vbInformation, "Achtung"
TextBoxleerER.SetFocus
Else
' Abfrage ob Buchungswert ungleich Summenwert
If CDbl(TextBoxB_ER.Value)  CDbl(TextBoxSummeER.Value) Then
MsgBox "Der Rechnungsbetrag stimmt nicht mit der Summe der Kontobuchnungen überein!",  _
vbInformation, "Achtung"
TextBoxleerER.SetFocus
Else
Cells(lngZeile, 1).Value = ComboBox_BuchungsdatumER.Value
Cells(lngZeile, 6).Value = TextBoxB_ER.Value * 1
Cells(lngZeile, 3).Value = ComboBox_DatenER.Value
Cells(lngZeile, 4).Value = ComboBox_VorgangER.Value
Cells(lngZeile, 7).Value = TextBox1.Value * 1
Cells(lngZeile, 8).Value = TextBox2.Value * 1
Cells(lngZeile, 9).Value = TextBox3.Value * 1
Cells(lngZeile, 10).Value = TextBox4.Value * 1
Cells(lngZeile, 11).Value = TextBox5.Value * 1
Cells(lngZeile, 12).Value = TextBox6.Value * 1
Cells(lngZeile, 13).Value = TextBox7.Value * 1
Cells(lngZeile, 14).Value = TextBox8.Value * 1
Cells(lngZeile, 15).Value = TextBox9.Value * 1
Cells(lngZeile, 16).Value = TextBox10.Value * 1
Cells(lngZeile, 17).Value = TextBox11.Value * 1
Cells(lngZeile, 18).Value = TextBox12.Value * 1
Cells(lngZeile, 19).Value = TextBox13.Value * 1
Cells(lngZeile, 20).Value = TextBox14.Value * 1
Cells(lngZeile, 21).Value = TextBox15.Value * 1
Cells(lngZeile, 22).Value = TextBox16.Value * 1
Cells(lngZeile, 23).Value = TextBox17.Value * 1
Cells(lngZeile, 24).Value = TextBox18.Value * 1
Cells(lngZeile, 25).Value = TextBox19.Value * 1
Cells(lngZeile, 26).Value = TextBox20.Value * 1
Cells(lngZeile, 27).Value = TextBox21.Value * 1
Cells(lngZeile, 28).Value = TextBox22.Value * 1
Cells(lngZeile, 29).Value = TextBox23.Value * 1
Cells(lngZeile, 30).Value = TextBox24.Value * 1
Cells(lngZeile, 31).Value = TextBox25.Value * 1
Cells(lngZeile, 32).Value = TextBox26.Value * 1
Cells(lngZeile, 33).Value = TextBox27.Value * 1
Cells(lngZeile, 34).Value = TextBox28.Value * 1
Cells(lngZeile, 35).Value = TextBox29.Value * 1
Cells(lngZeile, 36).Value = TextBox30.Value * 1
Cells(lngZeile, 37).Value = TextBox31.Value * 1
Cells(lngZeile, 38).Value = TextBox32.Value * 1
End If
End If
End Sub
Kann mir bitte Jemand weiterhelfen.
Vielen Dank fürs lesen und die Hilfe.
mfg, Andreas

4
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Ja Nein Abfrage
14.03.2018 12:36:17
yummi
Hallo Andreas,
das kannst so machen:

Sub tgest()
Dim iAntwort As Integer
iAntwort = MsgBox("Soll der Wert übernommen werden?", vbYesNo)
If iAntwort = vbYes Then
MsgBox "Ja"
End If
If iAntwort = vbNo Then
MsgBox "Nein"
End If
End Sub
Musst Du dir nur dahin bauen, wo Du es haben willst. Anstatt der MsgBox Ausgabe "ja" bzw "nein" kommt dann dein code.
Gruß
yummi
AW: Ja Nein Abfrage
14.03.2018 12:58:50
Andreas
Hallo yummi,
vielen Dank für deine Hilfe. Hab mal probiert deinen Tipp umzusetzen. Leider funktioniert es nicht wie gewünscht. Die Abfrage erscheint zwar bei einem positiven Wert in TextBoxB_ER. Gebe ich aber einen negativen Wert in TextBoxB_ER erfolgt keine Abfrage (so soll es ja sein), aber es erfolgt kein Eintrag in das Blatt.
Was habe ich falsch gemacht?
Hier mein geänderter Code:
Private Sub CommandButtonER_Click()
Dim lngZeile  As Long
lngZeile = Cells(5, 1).End(xlDown).Row + 1
Dim iAntwort As Integer
' Abfrage ob Pflichtfelder gefüllt sind
If ComboBox_BuchungsortER.ListIndex = -1 Or ComboBox_BuchungsdatumER.ListIndex = -1 Or  _
TextBoxB_ER.Value = 0 Or ComboBox_DatenER.Text = "" Or ComboBox_VorgangER.Text = "" Then
MsgBox "Bitte alle Pflichtfelder * füllen!", vbInformation, "Achtung"
TextBoxleerER.SetFocus
Else
' Abfrage ob Buchungswert ungleich Summenwert
If CDbl(TextBoxB_ER.Value)  CDbl(TextBoxSummeER.Value) Then
MsgBox "Der Rechnungsbetrag stimmt nicht mit der Summe der Kontobuchnungen überein!",  _
vbInformation, "Achtung"
TextBoxleerER.SetFocus
Else
If TextBoxB_ER.Value > 0 Then
iAntwort = MsgBox("Soll der Wert übernommen werden?", vbYesNo)
If iAntwort = vbNo Then
Me.TextBoxB_ER.Text = "0.00" 'gibt 0,00 aus
Me.TextBoxSummeER.Text = "0,00"
Me.TextBox1.Text = "0,00"
Me.TextBox2.Text = "0,00"
Me.TextBox3.Text = "0,00"
Me.TextBox4.Text = "0,00"
Me.TextBox5.Text = "0,00"
Me.TextBox6.Text = "0,00"
Me.TextBox7.Text = "0,00"
Me.TextBox8.Text = "0,00"
Me.TextBox9.Text = "0,00"
Me.TextBox10.Text = "0,00"
Me.TextBox11.Text = "0,00"
Me.TextBox12.Text = "0,00"
Me.TextBox13.Text = "0,00"
Me.TextBox14.Text = "0,00"
Me.TextBox15.Text = "0,00"
Me.TextBox16.Text = "0,00"
Me.TextBox17.Text = "0,00"
Me.TextBox18.Text = "0,00"
Me.TextBox19.Text = "0,00"
Me.TextBox20.Text = "0,00"
Me.TextBox21.Text = "0,00"
Me.TextBox22.Text = "0,00"
Me.TextBox23.Text = "0,00"
Me.TextBox24.Text = "0,00"
Me.TextBox25.Text = "0,00"
Me.TextBox26.Text = "0,00"
Me.TextBox27.Text = "0,00"
Me.TextBox28.Text = "0,00"
Me.TextBox29.Text = "0,00"
Me.TextBox30.Text = "0,00"
Me.TextBox31.Text = "0,00"
Me.TextBox32.Text = "0,00"
TextBoxleerER.SetFocus
End If
If iAntwort = vbYes Then
Cells(lngZeile, 1).Value = ComboBox_BuchungsdatumER.Value
Cells(lngZeile, 6).Value = TextBoxB_ER.Value * 1
Cells(lngZeile, 3).Value = ComboBox_DatenER.Value
Cells(lngZeile, 4).Value = ComboBox_VorgangER.Value
Cells(lngZeile, 7).Value = TextBox1.Value * 1
Cells(lngZeile, 8).Value = TextBox2.Value * 1
Cells(lngZeile, 9).Value = TextBox3.Value * 1
Cells(lngZeile, 10).Value = TextBox4.Value * 1
Cells(lngZeile, 11).Value = TextBox5.Value * 1
Cells(lngZeile, 12).Value = TextBox6.Value * 1
Cells(lngZeile, 13).Value = TextBox7.Value * 1
Cells(lngZeile, 14).Value = TextBox8.Value * 1
Cells(lngZeile, 15).Value = TextBox9.Value * 1
Cells(lngZeile, 16).Value = TextBox10.Value * 1
Cells(lngZeile, 17).Value = TextBox11.Value * 1
Cells(lngZeile, 18).Value = TextBox12.Value * 1
Cells(lngZeile, 19).Value = TextBox13.Value * 1
Cells(lngZeile, 20).Value = TextBox14.Value * 1
Cells(lngZeile, 21).Value = TextBox15.Value * 1
Cells(lngZeile, 22).Value = TextBox16.Value * 1
Cells(lngZeile, 23).Value = TextBox17.Value * 1
Cells(lngZeile, 24).Value = TextBox18.Value * 1
Cells(lngZeile, 25).Value = TextBox19.Value * 1
Cells(lngZeile, 26).Value = TextBox20.Value * 1
Cells(lngZeile, 27).Value = TextBox21.Value * 1
Cells(lngZeile, 28).Value = TextBox22.Value * 1
Cells(lngZeile, 29).Value = TextBox23.Value * 1
Cells(lngZeile, 30).Value = TextBox24.Value * 1
Cells(lngZeile, 31).Value = TextBox25.Value * 1
Cells(lngZeile, 32).Value = TextBox26.Value * 1
Cells(lngZeile, 33).Value = TextBox27.Value * 1
Cells(lngZeile, 34).Value = TextBox28.Value * 1
Cells(lngZeile, 35).Value = TextBox29.Value * 1
Cells(lngZeile, 36).Value = TextBox30.Value * 1
Cells(lngZeile, 37).Value = TextBox31.Value * 1
Cells(lngZeile, 38).Value = TextBox32.Value * 1
End If
End If
End If
End If
End Sub
Danke für die Hilfe.
mfg, Andreas
Anzeige
AW: Ja Nein Abfrage
14.03.2018 14:56:32
yummi
Hallo Andreas,
dann musst du den else Zweig für deine Abfrage, ob größer 0 auch programmieren, so :

Option Explicit
Private Sub CommandButtonER_Click()
Dim lngzeile  As Long
lngzeile = Cells(5, 1).End(xlDown).Row + 1
Dim iAntwort As Integer
' Abfrage ob Pflichtfelder gefüllt sind
If ComboBox_BuchungsortER.ListIndex = -1 Or ComboBox_BuchungsdatumER.ListIndex = -1 Or _
TextBoxB_ER.Value = 0 Or ComboBox_DatenER.Text = "" Or ComboBox_VorgangER.Text = "" Then
MsgBox "Bitte alle Pflichtfelder * füllen!", vbInformation, "Achtung"
TextBoxleerER.SetFocus
Else
' Abfrage ob Buchungswert ungleich Summenwert
If CDbl(TextBoxB_ER.Value)  CDbl(TextBoxSummeER.Value) Then
MsgBox "Der Rechnungsbetrag stimmt nicht mit der Summe der Kontobuchnungen überein!" _
, _
vbInformation, "Achtung"
Me.TextBoxleerER.SetFocus
Else
If TextBoxB_ER.Value > 0 Then
iAntwort = MsgBox("Soll der Wert übernommen werden?", vbYesNo)
If iAntwort = vbNo Then
Me.TextBoxB_ER.Text = "0.00" 'gibt 0,00 aus
Me.TextBoxSummeER.Text = "0,00"
Me.TextBox1.Text = "0,00"
Me.TextBox2.Text = "0,00"
Me.TextBox3.Text = "0,00"
Me.TextBox4.Text = "0,00"
Me.TextBox5.Text = "0,00"
Me.TextBox6.Text = "0,00"
Me.TextBox7.Text = "0,00"
Me.TextBox8.Text = "0,00"
Me.TextBox9.Text = "0,00"
Me.TextBox10.Text = "0,00"
Me.TextBox11.Text = "0,00"
Me.TextBox12.Text = "0,00"
Me.TextBox13.Text = "0,00"
Me.TextBox14.Text = "0,00"
Me.TextBox15.Text = "0,00"
Me.TextBox16.Text = "0,00"
Me.TextBox17.Text = "0,00"
Me.TextBox18.Text = "0,00"
Me.TextBox19.Text = "0,00"
Me.TextBox20.Text = "0,00"
Me.TextBox21.Text = "0,00"
Me.TextBox22.Text = "0,00"
Me.TextBox23.Text = "0,00"
Me.TextBox24.Text = "0,00"
Me.TextBox25.Text = "0,00"
Me.TextBox26.Text = "0,00"
Me.TextBox27.Text = "0,00"
Me.TextBox28.Text = "0,00"
Me.TextBox29.Text = "0,00"
Me.TextBox30.Text = "0,00"
Me.TextBox31.Text = "0,00"
Me.TextBox32.Text = "0,00"
TextBoxleerER.SetFocus
End If
If iAntwort = vbYes Then
TrageWerteEin lngzeile
End If
Else
TrageWerteEin lngzeile
End If
End If
End If
End Sub
Function TrageWerteEin(ByVal lngzeile As Long)
Cells(lngzeile, 1).Value = ComboBox_BuchungsdatumER.Value
Cells(lngzeile, 6).Value = TextBoxB_ER.Value * 1
Cells(lngzeile, 3).Value = ComboBox_DatenER.Value
Cells(lngzeile, 4).Value = ComboBox_VorgangER.Value
Cells(lngzeile, 7).Value = TextBox1.Value * 1
Cells(lngzeile, 8).Value = TextBox2.Value * 1
Cells(lngzeile, 9).Value = TextBox3.Value * 1
Cells(lngzeile, 10).Value = TextBox4.Value * 1
Cells(lngzeile, 11).Value = TextBox5.Value * 1
Cells(lngzeile, 12).Value = TextBox6.Value * 1
Cells(lngzeile, 13).Value = TextBox7.Value * 1
Cells(lngzeile, 14).Value = TextBox8.Value * 1
Cells(lngzeile, 15).Value = TextBox9.Value * 1
Cells(lngzeile, 16).Value = TextBox10.Value * 1
Cells(lngzeile, 17).Value = TextBox11.Value * 1
Cells(lngzeile, 18).Value = TextBox12.Value * 1
Cells(lngzeile, 19).Value = TextBox13.Value * 1
Cells(lngzeile, 20).Value = TextBox14.Value * 1
Cells(lngzeile, 21).Value = TextBox15.Value * 1
Cells(lngzeile, 22).Value = TextBox16.Value * 1
Cells(lngzeile, 23).Value = TextBox17.Value * 1
Cells(lngzeile, 24).Value = TextBox18.Value * 1
Cells(lngzeile, 25).Value = TextBox19.Value * 1
Cells(lngzeile, 26).Value = TextBox20.Value * 1
Cells(lngzeile, 27).Value = TextBox21.Value * 1
Cells(lngzeile, 28).Value = TextBox22.Value * 1
Cells(lngzeile, 29).Value = TextBox23.Value * 1
Cells(lngzeile, 30).Value = TextBox24.Value * 1
Cells(lngzeile, 31).Value = TextBox25.Value * 1
Cells(lngzeile, 32).Value = TextBox26.Value * 1
Cells(lngzeile, 33).Value = TextBox27.Value * 1
Cells(lngzeile, 34).Value = TextBox28.Value * 1
Cells(lngzeile, 35).Value = TextBox29.Value * 1
Cells(lngzeile, 36).Value = TextBox30.Value * 1
Cells(lngzeile, 37).Value = TextBox31.Value * 1
Cells(lngzeile, 38).Value = TextBox32.Value * 1
End Function

Gruß
yummi
Anzeige
AW: Ja Nein Abfrage
14.03.2018 15:16:43
Andreas
Hallo yummi,
vielen Dank für deine Hilfe. Das hätte ich wohl nie hinbekommen.
Jetzt funktioniert es wie es soll.
Einen schönen Tag noch,
mfg, Andreas

300 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige