Hallo!
Ich habe mit meiner VBA ein kleines Problem. Bei den Berechnungen wurde mir erst ein "@" nach dem "=" in den Formeln gesetzt. Damit wurde natürlich keine Formel berechnet. Bei der Formel "=SUMME(M" & vocStart & ":M" & vocEnd & ")" habe ich dies mit "Forumla2Local" wegebekommen und der Wert wird richtig berechnet.
Bei allen weitern Formeln kommt allerdings mit "Formula2Local" der Debugger! Also habe ich nur "Formula2" angewendet. Damit ist das "@" zwar nicht mehr in der Formel, es wird alles richtig dargestellt. Allerdings wird jetzt die Formel nicht berechnet. In der Zelle steht nun "#NAME?".
Ich habe es mit "Application.Calculate" für den entsprechenden Bereich versucht und noch ein paar Dingen. Damit es berechnet wird muss ich die Formeln anklicken und kurz bestätigen.
Hat jemand eine Idee wie ich Excel dazu bringe mir auch gleich den Wert zu berechnen?
Private Sub CommandButton1_Click()
' Arbeitsblatt Referenz
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Auswertung einzeln")
If ws Is Nothing Then
MsgBox "Das angegebene Arbeitsblatt wurde nicht gefunden."
Exit Sub
End If
Dim vvocStart As String, vvocEnd As String
Dim vocStart As String, vocEnd As String
Dim svocStart As String, svocEnd As String
' Eingaben sammeln aus den TextBoxen
vvocStart = TextBox1.Text
vvocEnd = TextBox6.Text
vocStart = TextBox5.Text
vocEnd = TextBox3.Text
svocStart = TextBox4.Text
svocEnd = TextBox2.Text
' Dynamische Bestimmung der Startzeile und füge eine Leerzeile zwischen die Tabelle und die Berechnungen ein
Dim lastRow As Integer
lastRow = ws.Cells(ws.Rows.Count, 11).End(xlUp).Row + 2 ' +2 für Leerzeile
Dim formulaText As String
' VVOC Bereich prüfen und Formel hinzufügen
If Not CheckBox3.Value Then
If IsNumeric(vvocStart) And IsNumeric(vvocEnd) Then
ws.Cells(lastRow, 11).Value = "VVOC < 5 µg/m³" ' Spalte K
formulaText = "=SUMMEWENNS(M" & vvocStart & ":M" & vvocEnd & ", K" & vvocStart & ":K" & vvocEnd & ", ""VVOC*"")"
ws.Cells(lastRow, 13).Formula2 = formulaText
lastRow = lastRow + 1
End If
End If
' VOC Bereich prüfen und Formel hinzufügen
If Not CheckBox5.Value Then
If IsNumeric(vocStart) And IsNumeric(vocEnd) Then
ws.Cells(lastRow, 11).Value = "VOC" ' Spalte K
formulaText = "=SUMME(M" & vocStart & ":M" & vocEnd & ")" ' Spalte M
ws.Cells(lastRow, 13).Formula2Local = formulaText
lastRow = lastRow + 1
ws.Cells(lastRow, 11).Value = "VOC < 5 µg/m³" ' Spalte K
formulaText = "=SUMMEWENN(K" & vocStart & ":K" & vocEnd & ","">0"",M" & vocStart & ":M" & vocEnd & ")"
ws.Cells(lastRow, 13).Formula2 = formulaText
lastRow = lastRow + 1
End If
End If
' SVOC Bereich prüfen und Formel hinzufügen
If Not CheckBox4.Value Then
If IsNumeric(svocStart) And IsNumeric(svocEnd) Then
ws.Cells(lastRow, 11).Value = "SVOC < 5 µg/m³" ' Spalte K
formulaText = "=SUMMEWENNS(M" & svocStart & ":M" & svocEnd & ", K" & svocStart & ":K" & svocEnd & ", ""SVOC*"")"
ws.Cells(lastRow, 13).Formula2 = formulaText
lastRow = lastRow + 1
End If
End If
Unload Me ' Schließt das UserForm
End Sub
|