关于Excel中计算一列数据中正数或负数连续出现的次数,并在另一列求和的公式。
2个回答
展开全部
alt+f11 左上角新建模块,插入下面代码 row=1000 填你自己的行数,数据都放第一列,f5执行
sub aa()
dim row=1000,count=0,sum=0
for i=1 to row
sum=sum+cells(i,1)
count=count+1
if cells(i,1) * cells(i+1)<0 then
cells(i,2)=sum
cells(i,3)=count
end if
next i
end sub
sub aa()
dim row=1000,count=0,sum=0
for i=1 to row
sum=sum+cells(i,1)
count=count+1
if cells(i,1) * cells(i+1)<0 then
cells(i,2)=sum
cells(i,3)=count
end if
next i
end sub
追答
Sub aa()
Row = 10
Count = 0
Sum = 0
For i = 2 To Row
Cells(i, 2) = ""
Cells(i, 3) = ""
Sum = Sum + Cells(i, 1)
Count = Count + 1
a = Cells(i, 1)
b = Cells(i + 1, 1)
If a = "" Then a = 0
If a = 0 Then
Cells(i, 2) = 0
Cells(i, 3) = 1
End If
If a * b <= 0 Then
Cells(i, 2) = Sum
Cells(i, 3) = Count
Sum = 0
Count = 0
End If
Next i
Cells(Row, 2) = Sum
Cells(Row, 3) = Count
End Sub
这个我是打开表格测试过了的,管保正确
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |