excel vba for循环问题

2024-11-25 15:10:20
推荐回答(2个)
回答1:

Next r上面加一句end if
If r.Value = r1 Then
r.Offset(0, 1) = -r.Offset(0, 1)
r.Offset(0, 2) = -r.Offset(0, 2)
end if
Next r

回答2:

Sub test()
Dim r As Range
Dim r1 As String
For Each r In Seet1.Cells
If r.Value = r1 Then
r.Offset(0, 1) = -r.Offset(0, 1)
r.Offset(0, 2) = -r.Offset(0, 2)
END IF '要加这一句
Next r ‘程序运行到这个位置提示“Next没有For”
End Sub