这是我写的代码,但它似乎没有用......
Private Sub area_Click()
Dim n As Double
Dim x, r, s, p, y, z As Integer
n = InputBox("No. of Points", "AREA COMPUTATION", "Insert here", 500, 700)
x = n + 1
Range("K2").Formula = "=SUM(E2+E2)"
For p = 3 to x
r = 3
For s = 0 to 1
r = r + s
Range("K" & p).Formula = "=SUM(Range("K" & (p-1)).Value + Range("E" & r).Value"
Next s
Next p
y = 3
For z = 3 to x Step 2
For w = 0 to x
y = 3 + w
Range("L2").Formula = "=E2*F2"
j = Range("K" & z).Value
u = Range("F" & y).Value
Range("L" & z).Formula = "u*j"
Next w
Next z
End Sub
答案 0 :(得分:0)
计算K2和L2单元格值,下面的代码将填充剩余值
Sub Foo()
last_row = 13
j = 3
k = 3
For i = 3 To last_row
'calculate values in column K
Cells(i, 11).Value = Cells(i - 1, 11).Value + Cells(j, 5).Value
If i Mod 2 <> 0 Then
'calculate values in column L when the row number is a odd number
Cells(i, 12).Value = Cells(i, 11).Value * Cells(k, 6).Value
k = k + 1
Else
j = j + 1
End If
Next i
'calculate sum
Cells(last_row + 1, 12).Value = "=sum(L2:L" & last_row & ")"
End Sub