在excel无效的Next 控件变量引用
发布网友
发布时间:2022-04-23 02:47
我来回答
共1个回答
热心网友
时间:2023-05-04 22:19
多了一个next i
next 后面的变量可以省略不写
代码最好写规范些,这样自己也比较好检查。
Private Sub CommandButton1_Click()
x = 0
If Cells(1, 1) <> "" Then
cx = Cells(1, 1)
For p = 1 To 3
Worksheets(p).Select
For i = 2 To 100
For j = 1 To 20
If Worksheets(p).Cells(i, j) = cx Then
Worksheets(p).Cells(i, j).Select
MsgBox "任意键继续..."
x = x + 1
End If
Next
Next
Next
End If
Worksheets(1).Select
Cells(1, 1).Select
If x = 0 Then
MsgBox "无相关记录"
End If
End Sub