Anzeige
Archiv - Navigation
776to780
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
776to780
776to780
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Addition von Textboxen

Addition von Textboxen
01.07.2006 18:02:19
Textboxen
Hallo,
ich habe 2 Fragen an euch:
1.)In einer Textbox (txtSumme)in einer UserForm sollen automatisch die Werte
aus 4 weiteren Textboxen addiert werden, unabhängig davon ob nur in einer
oder in mehreren Textboxen ein Wert steht.
Das Muster habe ich in der Recherche gefunden, allerdings nur mit 1und +2 und +3 und +4 statt 1+ und/oder +2 und/oder +3 und/oder +4.
Wie muss das Makro abgeändert werden?
2.)Wo muss ich den einzelnen Textboxen das Format "0,00€" zuweisen, damit aus
120 automatisch 120,00€ wird?
Vielen Dank schon mal im Voraus für eure Mühe!
Gruss
Max
https://www.herber.de/bbs/user/34791.xls

3
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Addition von Textboxen
01.07.2006 18:23:35
Textboxen
Hallo Max!
Probier's so.
' **********************************************************************
' Modul: UserForm1 Typ: Userform
' **********************************************************************

Private Sub txt1_Change()
allChange
End Sub

Private Sub txt1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
all_KeyPress KeyAscii
End Sub

Private Sub txt1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
all_Exit txt1
End Sub

Private Sub txt2_Change()
allChange
End Sub

Private Sub txt2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
all_KeyPress KeyAscii
End Sub

Private Sub txt2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
all_Exit txt2
End Sub

Private Sub txt3_Change()
allChange
End Sub

Private Sub txt3_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
all_KeyPress KeyAscii
End Sub

Private Sub txt3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
all_Exit txt3
End Sub

Private Sub txt4_Change()
allChange
End Sub

Private Sub txt4_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
all_KeyPress KeyAscii
End Sub

Private Sub txt4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
all_Exit txt4
End Sub

Private Sub allChange()
Dim tb As MSForms.Control
Dim dblS As Double
On Error Resume Next
For Each tb In Me.Controls
  If TypeOf tb Is MSForms.TextBox Then
    If tb.Name <> "txtSumme" Then
      If tb = "" Then tb = 0
      dblS = dblS + CDbl(tb)
    End If
  End If
Next
txtSumme = Format(dblS, "#,#0.00 €")
On Error GoTo 0
End Sub

Private Sub all_Exit(tb As MSForms.TextBox)
tb = Format(tb, "#,#0.00 €")
End Sub

Private Sub all_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
  Case 44, 48 To 57
  Case Else
    KeyAscii = 0
End Select
End Sub

Private Sub CommandButton1_Click()
If txtSumme.Text = "" Then
  Unload Me
  MsgBox "Ohne Betragsangabe erfolgt kein Eintrag", vbExclamation
Else
  Worksheets("Tabelle1").Cells(1, 1).Value = CDbl(txtSumme)
  Worksheets("Tabelle1").Cells(1, 2).Value = "(Darlehenssumme)"
  Unload Me
  MsgBox "Der Eintrag ist erfolgt!", vbInformation
End If
End Sub

Private Sub CommandButton2_Click()
Unload Me
End Sub


Gruß Sepp

Anzeige
AW: Addition von Textboxen-Erstes Problem gelöst
01.07.2006 18:28:17
Textboxen-Erstes
Hallo
FOlgendes ist der neue Code (ändert jeweils "" in 0 um)

Private Sub txt1_Change()
If txt1 <> "" Then
Worksheets("Tabelle2").Cells(1, 1).Value = "X"
Summe
End If
End Sub


Private Sub txt2_Change()
If txt2 <> "" Then
Worksheets("Tabelle2").Cells(2, 1).Value = "X"
Summe
End If
End Sub


Private Sub txt3_Change()
If txt3 <> "" Then
Worksheets("Tabelle2").Cells(3, 1).Value = "X"
Summe
End If
End Sub


Private Sub txt4_Change()
If txt4 <> "" Then
Worksheets("Tabelle2").Cells(4, 1).Value = "X"
Summe
End If
End Sub

Sub Summe()
If txt1 = "" Then txt12 = 0 Else txt12 = txt1
If txt2 = "" Then txt22 = 0 Else txt22 = txt2
If txt3 = "" Then txt32 = 0 Else txt32 = txt3
If txt4 = "" Then txt42 = 0 Else txt42 = txt4
txtSumme = (CDbl(txt12) + CDbl(txt22) + CDbl(txt32) + CDbl(txt42)) * 1
End Sub

Private Sub CommandButton1_Click()
If txtSumme.Text = "" Then
Unload Me
MsgBox "Ohne Betragsangabe erfolgt kein Eintrag", vbExclamation
Else
Worksheets("Tabelle1").Cells(1, 1).Value = txtSumme
Worksheets("Tabelle1").Cells(1, 2).Value = "(Darlehenssumme)"
Unload Me
MsgBox "Der Eintrag ist erfolgt!", vbInformation
End If
End Sub


Private Sub CommandButton2_Click()
Unload Me
End Sub

Gruss
Lukas
Bitte um Rückmeldung
Anzeige
Addition von Textboxen (Erledigt)
01.07.2006 19:22:28
Textboxen
Hallo Josef und Lukas,
vielen Dank euch beiden für die funktionierenden Lösungen!
Ich muss jetzt erstmal sehen ob England oder Portugal es noch gebacken bekommen....
Schönes Wochenende!
Gruß
Max

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige