使用Nothing键入不匹配错误,并且循环未终止

时间:2014-02-05 08:49:09

标签: excel-vba vba excel

我正在使用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 = ""

1 个答案:

答案 0 :(得分:4)

您只能将Is Nothing语句用于对象类型,但String不是对象。

更改

Loop Until pword Is Nothing

Loop Until pword = ""