[英]Repeatedly getting an error as `Type Mismatch` in the VBScript code
您能否告訴我代碼的以下部分出了什么問題? 在下面的代碼中反復收到錯誤,因為Type Mismatch
:
TotalRows=objExcel1.Application.WorksheetFunction.CountA(ob4.Columns(1))
'MsgBox(TotalRows)
ReDim ArrParent(TotalRows - 2)
ArrParent=ob4.Range("A2:" & "A" & TotalRows).Value 'here i am getting an error as said above
'Call to the subroutine
ParentPIDNumber ArrParent,ob3,ob2,ob4
碼
Sub FileredOpenProcessToDel(ob3,ob2,ob4)
Dim ColumnToFilter,TotalRows
Dim rngFilter,cel,str,rangesToRemove,x
Dim strToRemove : strToRemove = ""
Dim ArrParent
objExcel1.ScreenUpdating = False
objExcel1.Calculation = -4135 'xlCalculationManual
ColumnToFilter=objExcel1.Application.WorksheetFunction.CountA(ob4.Rows(1)) - 1
ob4.Range(ob4.Cells(1,ColumnToFilter),ob4.Cells(1,ColumnToFilter)).AutoFilter ColumnToFilter, "Open",,,True
'Dim rngFilter as Range
Set rngFilter = objExcel1.Application.Intersect(ob4.UsedRange,ob4.UsedRange.Offset(1),ob4.Columns(1)).SpecialCells(12)'xlCellTypeVisible
'MsgBox(rngFilter.Rows.Count)
REM Do While 1=1
REM 'Msgbox
REM Loop
'msgbox "Filtered range has " & rngFilter.Rows.Count & " rows."
str=""
For each cel in rngFilter
str = str & (cel.row) & ":" & (cel.row) & ","
Next
rangesToRemove = Split(str,",")
For x = UBOUND(rangesToRemove)-1 To LBOUND(rangesToRemove) Step -1
strToRemove = strToRemove & rangesToRemove(x)
If Len(strToRemove) > 200 then
ob4.Range(strToRemove).delete'str & rangesToRemove(x) & ":" & rangesToRemove(x) & ","
strToRemove = ""
Else
strToRemove = strToRemove & ","
End If
Next
If len(strToRemove) > 0 then
strToRemove = Mid(strToRemove, 1, Len(strToRemove) - 1)
'strToRemove = Left(strToRemove, Len(strToRemove) -1)
ob4.Range(strToRemove).delete
End If
ob4.AutoFilterMode = False
objExcel1.ScreenUpdating = True
objExcel1.Calculation = -4105 'xlCalculationAutomatic
TotalRows=objExcel1.Application.WorksheetFunction.CountA(ob4.Columns(1))
MsgBox(TotalRows)
'ReDim ArrParent(TotalRows - 2)
ArrParent=ob4.Range("A2:A" & TotalRows).value2
'MsgBox(ArrParent(1,0))
'Call to the subroutine
ParentPIDNumber ArrParent,ob3,ob2,ob4
End Sub
謝謝,
嘗試使用Application.Transpose將值存儲到一維數組||中。
ArrParent=Application.Transpose(ob4.Range("A2:A" & TotalRows).value)
編輯
我相信范圍數組始終是二維數組。 轉置用於將數據轉換為一維數組。
您最初是將ArrParent分配給array(0,968),而不是想要的是array(968)。
我認為我的解釋是正確的。 如果我不是,請有人糾正我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.