level 2
Sub CalculateBasedOnConditions()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("数据") '设置要操作的工作表,根据实际修改工作表名称
Dim lastRow As Long
lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row '找到B列最后一个有数据的行
Dim i As Long
For i = 3 To lastRow '从第3行开始遍历到B列最后有数据的行
If Not IsEmpty(ws.Cells(i, "B")) Then
Dim q As Double
Dim r As Double
Dim s As Double
Dim t As Double
Dim u As Double
Dim v As Double
Dim w As Double
Dim x As Double
Dim y As Double
q = ws.Cells(i, "BA") + ws.Cells(i, "BQ") - ws.Cells(i, "AS") - ws.Cells(i, "BI") - ws.Cells(i, "BY") + ws.Cells(i, "CG")
r = ws.Cells(i, "BB") + ws.Cells(i, "BR") - ws.Cells(i, "AT") - ws.Cells(i, "BJ") - ws.Cells(i, "BZ") + ws.Cells(i, "CH")
s = ws.Cells(i, "BC") + ws.Cells(i, "BS") - ws.Cells(i, "AU") - ws.Cells(i, "BK") - ws.Cells(i, "CA") + ws.Cells(i, "CI")
t = ws.Cells(i, "BD") + ws.Cells(i, "BT") - ws.Cells(i, "AV") - ws.Cells(i, "BL") - ws.Cells(i, "CB") + ws.Cells(i, "CJ")
u = ws.Cells(i, "BE") + ws.Cells(i, "BU") - ws.Cells(i, "AW") - ws.Cells(i, "BM") - ws.Cells(i, "CC") + ws.Cells(i, "CK")
v = ws.Cells(i, "BF") + ws.Cells(i, "BV") - ws.Cells(i, "AX") - ws.Cells(i, "BN") - ws.Cells(i, "CD") + ws.Cells(i, "CL")
w = ws.Cells(i, "BG") + ws.Cells(i, "BW") - ws.Cells(i, "AY") - ws.Cells(i, "BO") - ws.Cells(i, "CE") + ws.Cells(i, "CM")
x = q + r + s + t + u + v + w
y = ws.Cells(i, "J") * x
ws.Cells(i, "P") = q
ws.Cells(i, "Q") = r
ws.Cells(i, "R") = s
ws.Cells(i, "S") = t
ws.Cells(i, "T") = u
ws.Cells(i, "U") = v
ws.Cells(i, "V") = w
ws.Cells(i, "W") = x
ws.Cells(i, "X") = y
End If
Next i
End Sub
2024年11月15日 14点11分