您能否告诉我下面的代码有什么问题?在以下代码中反复收到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
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
谢谢,
答案 0 :(得分:1)
尝试使用Application.Transpose将值存储到1d数组||
ArrParent=Application.Transpose(ob4.Range("A2:A" & TotalRows).value)
修改强> 的
我相信范围数组总是二维数组。 Transpose用于将数据转换为一维数组。
您最初将ArrParent分配给数组(0,968)而不是您想要的数组(968)。
我认为我的解释是正确的。如果我不是,请有人纠正我。