請問下列部分代碼有什麼問題?在下面的代碼反覆得到一個錯誤Type Mismatch
:在VBScript代碼中重複出現類型不匹配的錯誤
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
CODE
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
感謝,
將什麼值分配給TotalRows? – Sam
@SamWard'totalrows'是第#1列中的數據的數量。請幫助我在這裏,我真的卡在這裏! –
我的意思是在錯誤發生之前什麼值是TotalRows?您可以添加一個斷點並逐步執行代碼,或者在錯誤發生之前添加Msgbox(TotalRows)。 – Sam