Übername von Daten
31.08.2023 16:01:16
Ron
mein Code soll aus einer Tabelle Spalte B Daten übernehmen, wo in der Spalte A das Wort "Summe" steht.
Nun übernimmt er aber alle Daten aus Spalte B.
Kann jemand helfen?
For i = 70 To last_row
If InStr(ws.Cells(i, "A").Value, "Summe") > 0 Then
Dim year As String
year = Replace(ws.Cells(i, "A").Value, "Summe", "")
year = Trim(year)
If IsNumeric(year) Then
found = True
' Überprüft, ob das ausgelesene Jahr mit den Labels 1 bis 5 übereinstimmt, bevor die Werte zugewiesen werden
If year = Me.Label1.Caption Then
If Me.TextBox1 = "" Then
Me.TextBox1.Value = ws.Cells(i, "B").Value
TextBox1.Text = Format(TextBox1.Text, "#,##0.00")
Else
Me.TextBox1.Value = TextBox1.Value + ws.Cells(i, "B").Value
TextBox1.Text = Format(TextBox1.Text, "#,##0.00")
End If
ElseIf year = Me.Label2.Caption Then
If Me.TextBox2 = "" Then
Me.TextBox2.Value = ws.Cells(i, "B").Value
TextBox2.Text = Format(TextBox2.Text, "#,##0.00")
Else
Me.TextBox2.Value = TextBox2.Value + ws.Cells(i, "B").Value
TextBox2.Text = Format(TextBox2.Text, "#,##0.00")
End If
ElseIf year = Me.Label3.Caption Then
If Me.TextBox3 = "" Then
Me.TextBox3.Value = ws.Cells(i, "B").Value
TextBox3.Text = Format(TextBox3.Text, "#,##0.00")
Else
Me.TextBox3.Value = TextBox3.Value + ws.Cells(i, "B").Value
TextBox3.Text = Format(TextBox3.Text, "#,##0.00")
End If
ElseIf year = Me.Label4.Caption Then
If Me.TextBox4 = "" Then
Me.TextBox4.Value = ws.Cells(i, "B").Value
TextBox4.Text = Format(TextBox4.Text, "#,##0.00")
Else
Me.TextBox4.Value = TextBox4.Value + ws.Cells(i, "B").Value
TextBox4.Text = Format(TextBox4.Text, "#,##0.00")
End If
ElseIf year = Me.Label5.Caption Then
If Me.TextBox5 = "" Then
Me.TextBox5.Value = ws.Cells(i, "B").Value
TextBox5.Text = Format(TextBox5.Text, "#,##0.00")
Else
Me.TextBox5.Value = TextBox5.Value + ws.Cells(i, "B").Value
TextBox5.Text = Format(TextBox5.Text, "#,##0.00")
End If
End If
End If
End If
Next i
Danke