Sub UpdateAccumulatedValues()
Dim ws As Worksheet
Set ws = ActiveSheet ' 使用当前活动的工作表
Dim lastRow As Long
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row ' 找到A列最后一个非空单元格的行号
' 从第二行开始循环,因为第一行可能是标题
Dim i As Long
For i = 2 To lastRow
' 检查B列和A列的单元格是否包含数字
If IsNumeric(ws.Cells(i, "B").Value) And IsNumeric(ws.Cells(i, "A").Value) Then
' 计算新的累计数据
Dim newAccumulated As Double
newAccumulated = ws.Cells(i, "B").Value + ws.Cells(i, "A").Value
' 将新的累计数据回填到B列
ws.Cells(i, "B").Value = newAccumulated
Else
' 如果不是数字,可以选择在这里处理错误或者跳过
MsgBox "非数字数据在行 " & i & ",请检查数据。"
End If
Next i
End Sub