我希望弹出一个MsgBox,其中列出了缺少信息(电话号码或地址)的姓名。到目前为止,我有:
Dim missing As String
Do While Cells(i, 1).Value <> ""
If StrComp(Cells(i, 1), "Need address") = 0 Then missing = Cells(i - 2, 1)
Loop
MsgBox missing电子表格的格式为A列中的所有客户信息按以下顺序排列:
名字
电话号码
地址
到目前为止,我只得到了一个1004运行时错误
发布于 2015-06-22 19:53:36
你必须初始化和i
Sub dural()
Dim missing As String, i As Long
i = 1
Do While Cells(i, 1).Value <> ""
If StrComp(Cells(i, 1), "Need address") = 0 Then missing = Cells(i - 2, 1)
i = i + 1
Loop
MsgBox missing
End Sub在不初始化i的情况下,它从开始,这就是错误的根源。
发布于 2015-06-22 19:53:04
“i”是从哪里开始的?因为(i - 2 )可以是-2,它不是excel中的行号。
https://stackoverflow.com/questions/30979078
复制相似问题