我正在使用vba宏来查找some_col
中的非空单元格,从第1行开始。当我找到它时,我想将其分配给pword
以及单元格的值ajdacent列到cword
。但似乎在运行此代码时,循环不会终止,因为即使在找到非空单元格之后,它也没有结束。 (另外,如果我使用pword = Nothing
它会显示类型不匹配错误,并且在msdn网站上,他们将此作为用于空字符串的选项。)
谁能告诉我这里有什么问题?
Dim pword As String
Dim cword As String
Dim present_row As Long
pword = ""
Cells(1, some_col).Activate
MsgBox "Active cell: " & ActiveCell.Address
Do
If Not ActiveCell.value = "" Then
pword = ActiveCell.value
cword = ActiveCell.Offset(0, 1).value
End If
ActiveCell.Offset(1, 0).Activate
present_row = ActiveCell.Row
Loop Until pword = ""
答案 0 :(得分:4)
您只能将Is Nothing
语句用于对象类型,但String
不是对象。
更改
Loop Until pword Is Nothing
到
Loop Until pword = ""