查找 – 在SearchDirection中放置variables会导致运行时错误13 – types不匹配

为什么这个工作:

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 – types不匹配?

SearchDirection不是Stringtypes的参数,而是XlSearchDirectiontypes的XlSearchDirection ,因为不存在从一个到另一个的转换,所以不能将string传递给它。 xlNext"xlNext"不一样

使用以下代码:

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

方向是一个枚举input链接描述这里需要是一个数字或枚举equiv