急!!!!!VBA 运行的时候出现run-time error '13' Type Mismatch
VBA运行的时候出现run-timeerror'13'TypeMismatch,并指向arrA(j)=arrA(j)+arr(i,j)+8出错,是不是arrA和arr的类...
VBA 运行的时候出现run-time error '13'
Type Mismatch, 并指向arrA(j) = arrA(j) + arr(i, j) + 8 出错,是不是arrA和arr的类型不匹配?
Sub Jan()
Dim d1 As New Dictionary, d2 As New Dictionary, arr, arr1, arrA(1 To 15) As Double, arrB(1 To 15) As Double
Dim mydao As Date, mydaq As Date
Dim i As Integer, j As Integer
arr = Sheets("Jan").range("A1:AJ" & Sheets("Jan").range("A65536").End(xlUp).Row)
arr1 = Sheets("Jan").range("AZ6:BA" & Sheets("Jan").range("AZ6").End(xlDown).Row)
Set d1 = New Dictionary
Set d2 = New Dictionary
For i = 3 To UBound(arr)
If Not d1.exists(arr(i, 1)) Then
d1(arr(i, 1)) = i
End If
Next
For i = 1 To UBound(arr1)
If Not d2.exists(arr1(i, 1)) Then
d2(arr1(i, 1)) = i
End If
Next
mydao = Cells(7, 45)
mydaq = Cells(7, 46)
For j = 3 To UBound(arr, 2)
For i = d1(mydao) To d1(mydaq)
If Not d2.exists(arr(i, 1)) Then
arrA(j) = arrA(j) + arr(i, j) + 8
arrB(j) = arrB(j) + arr(i, j)
Else
arrA(j) = arrA(j) + arr(i, j)
arrB(j) = arrB(j) + arr(i, j)
End If
Next
Next
Cells(7, 51) = Application.Max(arrB())
Cells(7, 54) = Application.Sum(arrA())
Set arr = Nothing
Set arr1 = Nothing
End Sub 展开
Type Mismatch, 并指向arrA(j) = arrA(j) + arr(i, j) + 8 出错,是不是arrA和arr的类型不匹配?
Sub Jan()
Dim d1 As New Dictionary, d2 As New Dictionary, arr, arr1, arrA(1 To 15) As Double, arrB(1 To 15) As Double
Dim mydao As Date, mydaq As Date
Dim i As Integer, j As Integer
arr = Sheets("Jan").range("A1:AJ" & Sheets("Jan").range("A65536").End(xlUp).Row)
arr1 = Sheets("Jan").range("AZ6:BA" & Sheets("Jan").range("AZ6").End(xlDown).Row)
Set d1 = New Dictionary
Set d2 = New Dictionary
For i = 3 To UBound(arr)
If Not d1.exists(arr(i, 1)) Then
d1(arr(i, 1)) = i
End If
Next
For i = 1 To UBound(arr1)
If Not d2.exists(arr1(i, 1)) Then
d2(arr1(i, 1)) = i
End If
Next
mydao = Cells(7, 45)
mydaq = Cells(7, 46)
For j = 3 To UBound(arr, 2)
For i = d1(mydao) To d1(mydaq)
If Not d2.exists(arr(i, 1)) Then
arrA(j) = arrA(j) + arr(i, j) + 8
arrB(j) = arrB(j) + arr(i, j)
Else
arrA(j) = arrA(j) + arr(i, j)
arrB(j) = arrB(j) + arr(i, j)
End If
Next
Next
Cells(7, 51) = Application.Max(arrB())
Cells(7, 54) = Application.Sum(arrA())
Set arr = Nothing
Set arr1 = Nothing
End Sub 展开
展开全部
声明一下arr的类型,要不然默认是字符串类型
追问
没声明的话,不是默认是: Variant 么。。。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你把Dictionary 这个自定义的类型 方便也贴出来吗
更多追问追答
追问
这是所有的代码了。自定义在引用那块加载了一下
追答
找到原因了
你的代码
arrA(1 To 15) As Double, arrB(1 To 15) As Double
换成
arrA(1 To 65536) As Double, arrB(1 To 65536) As Double
就可以了
都超出范围了 干嘛设置这么小呢
你试一试吧 我这里是成功的
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我电脑中没有Dictionary,所以不好调试。
楼主只要单步调试一下,就能发现问题出在什么地方了。
楼主只要单步调试一下,就能发现问题出在什么地方了。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询