AW: automatisiertes Rechnen in Unserfom
31.10.2018 11:12:55
Werner
Hallo Thomas,
der Fehler tritt deshalb auf, weil/wenn zum Zeitpunkt der Prüfung der TextBox609 diese TextBox leer ist.
Ich kenne deinen Programmablauf nicht und weiß auch nicht, welche Werte wann, wie erfasst werden. Zumindest beim Code deiner Schaltfläche "übernehmen" wird die TextBox609 nirgends befüllt.
Du mußt entweder dafür sorgen, dass die Prüfung auf die TextBox609, das hier
If Val(Controls("TextBox" & iA)) * 1.2 > CDbl(TextBox609) Then
Controls("Textbox" & iA) = Format(TextBox609, "#,###")
Else
Controls("TextBox" & (iA + 51)) = Format(Val(Controls("TextBox" & iA)) * 1.2, "#,###")
End If
erst ausgeführt wird, wenn die TextBox609 auch gefüllt ist, oder du baust noch eine Prüfung ein ob die TextBox609 einen Wert hat oder nicht.
Das habe ich in dem Code hier mal gemacht. Ich prüfe, ob die TextBox609 leer ist, wenn ja, dann wird eine 0 in die TextBox609 geschrieben.
So wird die Fehlerauslösung verhindert. Ob das dann mit deinen Berechnungen so noch passt weiß ich nicht.
Der Code ist auch noch etwas eingekürzt. Die Variablendeklarierung gehört in den Kopf des Makros und nicht mitten ins Makro. Zudem macht es auch keinen Sinn mehr Laufvariablen als Integer zu deklarieren.
Private Sub CommandButton25_Click()
Dim J As Long, i As LongD, iA As Long, iB As Long, iC As Long, iD As Long
Dim iE As Long, iG As Long, iG As Long, iH As Long, iJ As Long, iK As Long
CommandButton23.Locked = False
CommandButton24.Locked = False
CommandButton25.Locked = True
'TX Boxen Einkommen und AHV-Rente sperren machen'
For J = 508 To 609
Me.Controls("TextBox" & J).Locked = True
Me.Controls("TextBox" & J).BackColor = &H8000000F
Me.Controls("TextBox" & J).SpecialEffect = fmSpecialEffectFlat
Next
'Werte Einkommen eintragen in UF und in Arbeitsblatt übertragen'
With Sheets("Skala 44")
For i = 508 To 558
.Range("A" & i - 501) = Me.Controls("TextBox" & i)
Next i
'Werte AHV-/IV-Rente eintragen in UF und in Arbeitsblatt übertragen'
For i = 559 To 609
.Range("C" & i - 552) = Me.Controls("TextBox" & i)
Next i
End With
'Berechnen Altersrente Witwen (monatlich) anhand AHV-/IV-Rente, Faktor 1.2'
For iA = 559 To 609
'### Fehler tritt auf, weil/wenn die TextBox609 leer ist #####
If Me.TextBox = "" Then Me.TextBox = 0
If Val(Controls("TextBox" & iA)) * 1.2 > CDbl(textbox609) Then
Controls("Textbox" & iA) = Format(textbox609, "#,###")
Else
Controls("TextBox" & (iA + 51)) = Format(Val(Controls("TextBox" & iA)) * 1.2, "#,###")
End If
Next iA
'Berechnen Witwenrente (monatlich) anhand AHV-/IV-Rente, Faktor 0.8'
For iB = 559 To 609
Controls("TextBox" & (iB + 102)) = Format(Val(Controls("TextBox" & iB)) * 0.8, "#,###")
Next iB
'Berechnen Waisen-/Kinderrente (monatlich) anhand AHV-/IV-Rente, Faktor 0.4'
For iC = 559 To 609
Controls("TextBox" & (iC + 153)) = Format(Val(Controls("TextBox" & iC)) * 0.4, "#,###")
Next iC
'Berechnen Waisen-/Kinderrente 60% (monatlich) anhand AHV-/IV-Rente, Faktor 0.6'
For iD = 559 To 609
Controls("TextBox" & (iD + 204)) = Format(Val(Controls("TextBox" & iD)) * 0.6, "#,###")
Next iD
'Berechnen Alter-IV-Rente (jährlich) anhand AHV-/IV-Rente, Faktor 12'
For iE = 559 To 609
Controls("TextBox" & (iE + 255)) = Format(Val(Controls("TextBox" & iE)) * 12, "#,###")
Next iE
'Berechnen Alterrente, Witwen (jährlich) anhand AHV-/IV-Rente, Faktoren 1.2 * 12'
For iG = 559 To 609
Controls("TextBox" & (iG + 306)) = Format(Val(Controls("TextBox" & iG)) * 1.2 * 12, "#,###")
Next iG
'Berechnen Witwenrente (jährlich) anhand AHV-/IV-Rente, Faktoren 0.8 * 12'
For iH = 559 To 609
Controls("TextBox" & (iH + 357)) = Format(Val(Controls("TextBox" & iH)) * 0.8 * 12, "#,###")
Next iH
'Berechnen Waisenrente (jährlich) anhand AHV-/IV-Rente, Faktoren 0.4 * 12'
For iJ = 559 To 609
Controls("TextBox" & (iJ + 408)) = Format(Val(Controls("TextBox" & iJ)) * 0.4 * 12, "#,###")
Next iJ
'Berechnen Witwenrente 60% (jährlich) anhand AHV-/IV-Rente, Faktoren 0.6 * 12'
For iK = 559 To 609
Controls("TextBox" & (iK + 459)) = Format(Val(Controls("TextBox" & iK)) * 0.6 * 12, "#,###")
Next iK
End Sub
Gruß Werner