excel vba 这个代码错在哪里?

来源:百度知道 编辑:UC知道 时间:2024/07/01 04:47:10
'Public Sub check()
'For i = 2 To 652
'Do Until k = 10
'k = k + 1
' m = Cells(i, k)
'If m < 0 Then
'Cells(i, k) = 0
'End If
'Loop
'Next

'End Sub

Public Sub check()
For i = 2 To 652

If Cells(i, 1) < 0 Then
Cells(i, 1) = 0
End If
If Cells(i, 2) < 0 Then
Cells(i, 2) = 0
End If
If Cells(i, 3) < 0 Then
Cells(i, 3) = 0
End If
If Cells(i, 4) < 0 Then
Cells(i, 4) = 0
End If
If Cells(i, 5) < 0 Then
Cells(i, 5) = 0
End If

If Cells(i, 6) < 0 Then
Cells(i, 6) = 0
End If
If Cells(i, 7) < 0 Then
Cells(i, 7) = 0
End If
If Cells(i, 8) < 0 Then
Cells(i, 8) = 0
End If
If Cells(i, 9) < 0 Then
Cells(i, 9) = 0
End If
If Cells(i, 10) < 0 Then
Cells(i, 10) = 0
End If
Next

Public Sub check()
For i = 2 To 652
K=0 '此处K必须赋初值0 ,就是说每新起一行都从第一列单元格开始处理
Do Until k = 10
k = k + 1
'm = Cells(i, k)
m=Cells(i,k).value '你的并没有错,但不是一个好的习惯,因为容易被看成是对象的赋值
If m < 0 Then
Cells(i, k) = 0
End If
Loop
Next
End Sub

for i=2 to 625
for j=1 to 10
if cells(i,j)<0 then
cells(i,j)=0
endif
next j,i

Public Sub check()
For i = 2 To 652
k=0 '注意加的这一行,每次循环先要给K赋值0
Do Until k = 10
k = k + 1
m = Cells(i, k)
If m < 0 Then
Cells(i, k) = 0
End If
Loop
Next
End Sub