在vbs中调用Range.SpecialCells提示错误“无法找到您正在搜索的数据”

时间:2015-01-29 08:17:50

标签: excel vbscript

我使用以下vba来搜索行中的非空单元格:

Set inputItems = inputDataWorkSheet.Range(inputStartColName & endProductRow & ":" & inputEndColName & endProductRow)
Set nonEmptyCells = inputItems.SpecialCells(xlCellTypeConstants) 
for each nonEmptyCell in nonEmptyCells
    debug.print nonEmptyCell.address
next 

它工作正常,但是,当在vbs中调用Range.SpecialCells时,它会提示以下错误消息:

cannot find the data you're searching for

这是vbs代码:

Set inputItems = inputDataWorkSheet.Range(inputStartColName & endProductRow & ":" & inputEndColName & endProductRow)
Set nonEmptyCells = inputItems.SpecialCells(2) 'where 2 mean xlCellTypeConstants

for each nonEmptyCell in nonEmptyCells
    WScript.StdOut.WriteLine nonEmptyCell.address
next 

我修改了代码如下:

on error resume next
Set inputItems = inputDataWorkSheet.Range(inputStartColName & endProductRow & ":" & inputEndColName & endProductRow)
Set nonEmptyCells = inputItems.SpecialCells(2) 'where 2 mean xlCellTypeConstants

for each nonEmptyCell in nonEmptyCells
    WScript.StdOut.WriteLine nonEmptyCell.address
next 

它提示“语法错误”,你介意告诉我如何解决它吗?

非常感谢

0 个答案:

没有答案