关于vba的问题 为什么运行 会提示 end if 没有if 块

2025-03-24 18:54:05
推荐回答(2个)
回答1:

呵呵,代码有个小错误
if 条件 then 代码
如果写在一行,就不用end if了
如果代码写到下一行,就需要用end if了

回答2:

改成:
Private Sub CommandButton1_Click()
Dim i As Single
For i = 1 To 200
If Cells(i, 1) = "城市" Then Cells(i, 2).Value = 2
Next i
End Sub

或者:
Private Sub CommandButton1_Click()
Dim i As Single
For i = 1 To 200
If Cells(i, 1) = "城市" Then
Cells(i, 2).Value = 2
End If
Next i
End Sub