VBScript运行时错误

我有两个Excels作为input。 我正在从一个Excel中取值,并将其作为parameter passing给其他Excel应用filter。 一旦filter打开,我正在读取列中的过滤值并尝试匹配下面的代码中提到的条件。 而一切正常工作到这个地方。 一旦我得到特定的匹配,我必须写回到第一个Excel,但我得到运行时错误,这样做。

strPath = "C:\Users\PSingh\Desktop\CodeInventory.xlsx" strPath1 = "C:\Users\PSingh\Desktop\MyScripts\Processes.xlsx" Dim rows Set objExcel1 = CreateObject("Excel.Application") objExcel1.Visible = True Set objExcel2 = CreateObject("Excel.Application") objExcel2.Visible = True Set objDict = CreateObject("Scripting.Dictionary") objDict.CompareMode = vbTextCompare Const xlUp = -4162 Const xlCellTypeVisible = 12 Dim a(), val objExcel1.Workbooks.Open(strPath1) With objExcel1.Activeworkbook.Sheets("Sheet1") rowcount = .Range("A" & .Rows.Count).End(xlUp).Row MsgBox rowcount End With Redim Preserve a(rowcount) For i=1 To rowcount a(i) = objExcel1.Activeworkbook.Sheets("Sheet1").Cells(i,1).Value objDict(a(i)) = a(i) 'msgbox a(i) Next n = objDict.Items objExcel2.Workbooks.Open(strPath) For i=0 To UBound(n) With objExcel2.Activeworkbook.Sheets("All") .Range("A1").AutoFilter 19, "="&n(i) 'rows=.usedrange.columns(1).specialcells(xlCellTypeVisible) For Each cl In objExcel2.Activeworkbook.Sheets("All").UsedRange.Columns(12).SpecialCells(xlCellTypeVisible) If (InStr(cl, "Seq") <> 0 Or InStr(cl,"seq")) <> 0 Then objExcel1.Activeworkbook.Sheets("Sheet1").Cells(i,2) = "Data" 'Not Working Exit For End If Next End With Next 

尝试一下,

 objExcel1.Activeworkbook.Sheets("Sheet1").Cells(i + 1, 2) = "Data" 

你循环i开始在For i = 0 to ... B列中没有零行。