.Find - 将变量放入SearchDirection导致运行时错误13 - 类型不匹配

时间:2016-11-09 10:23:59

标签: excel vba excel-vba

为什么这样做:

Set rowNonBlankFound = Rows(rowToUse).Find(what:="*", after:=Cells(rowToUse, leftMostCol), LookIn:=xlValues, SearchDirection:=xlNext)

但这并不是:

Dim direction As String direction = "xlNext" Set rowNonBlankFound = Rows(rowToUse).Find(what:="*", after:=Cells(rowToUse, leftMostCol), LookIn:=xlValues, SearchDirection:=direction)

我得到运行时错误13 - 类型不匹配?

2 个答案:

答案 0 :(得分:1)

SearchDirection不是String类型的参数,而是XlSearchDirection类型的参数,因为没有从一个转换到另一个,所以不能将字符串传递给它。 xlNext"xlNext"

不同

使用以下代码:

Dim direction As XlSearchDirection
direction = xlNext
Set rowNonBlankFound = Rows(rowToUse).Find(what:="*", after:=Cells(rowToUse, leftMostCol), LookIn:=xlValues, SearchDirection:=direction)

答案 1 :(得分:0)

方向是枚举enter link description here需要是数字或枚举等效