为什么运行会提示 end if 没有 if 块?

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

冉冉说
浏览 157回答 2
2回答

慕娘9325324

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

阿晨1998

改成:Private Sub CommandButton1_Click()Dim i As SingleFor i = 1 To 200If Cells(i, 1) = "城市" Then Cells(i, 2).Value = 2Next iEnd Sub或者:Private Sub CommandButton1_Click()Dim i As SingleFor i = 1 To 200If Cells(i, 1) = "城市" ThenCells(i, 2).Value = 2End IfNext iEnd Sub
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

数据结构