VBScript运行时错误

VBScript运行时错误

问题描述:

我有两个Excels作为输入。我从一个excel中取值,并将其作为参数传递给其他应用过滤器的excel。一旦过滤器打开,我正在读取列中的过滤值并尝试匹配下面代码中提到的条件。一切正常工作到这个地方。一旦我得到了特定的匹配,我必须将它写回第一个Excel,但是我在这样做时遇到了运行时错误。VBScript运行时错误

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" 

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