|
楼主 |
发表于 2015-12-31 14:15
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 hyjianjian 于 2015-12-31 14:18 编辑
蓝版:代码报错,“13”错误代码 类型不匹配。 Cells(n, 1).Resize(1, UBound(arr, 2)) = Application.Index(arr, ks, 0)
恳请指正
- Sub l2()
- Dim myPath$, myName$, arr1(), r%, aa, j&, ks, js
- Dim arr, i&, cz, n&, ii&, d, t
- Application.ScreenUpdating = False
- Set d = CreateObject("scripting.dictionary")
- Sheet2.Activate: Cells.Clear
- mypath = ThisWorkbook.Path & ""
- myName = "号口车种.xls"
- With GetObject(mypath & myName)
- arr = .Sheets(2).UsedRange
- For i = 2 To UBound(arr)
- If arr(i, 3) = 0 Then
- r = r + 1
- ReDim Preserve arr1(1 To r)
- arr1(r) = i
- d(arr(i, 6)) = d(arr(i, 6)) & r & ","
- End If
- Next
- .Close False
- End With
- cz = Sheet1.[a1].CurrentRegion
- For ii = 2 To UBound(cz)
- n = n + 1
- Cells(n, 1) = cz(ii, 1)
- If d.exists(cz(ii, 1)) Then
- t = d(cz(ii, 1))
- t = Left(t, Len(t) - 1)
- If InStr(t, ",") Then
- aa = Split(t, ",")
- For j = 0 To UBound(aa)
- If Val(aa(j)) <> r Then
- js = arr1(Val(aa(j)) + 1) - 1
- Else
- js = UBound(arr)
- End If
- ks = arr1(Val(aa(j)))
- n = n + 1
- Cells(n, 1).Resize(1, UBound(arr, 2)) = Application.Index(arr, ks, 0)
- For i = ks + 1 To js
- If Left(arr(i, 13), 1) = "S*" And arr(i, 9) > 0 Then
- n = n + 1
- Cells(n, 1).Resize(1, UBound(arr, 2)) = applecation.Index(arr, i, 0)
- End If
- Next
- Next
- Else
- If t <> r Then
- js = arr1(t + 1) - 1
- Else
- js = UBound(arr)
- End If
- ks = arr1(t)
- n = n + 1
- Cells(n, 1).Resize(1, UBound(arr, 2)) = Application.Index(arr, ks, 0)
- For i = ks + 1 To js
- If Left(arr(i, 13), 1) = "S*" And arr(i, 9) > 0 Then
- n = n + 1
- Cells(n, 1).Resize(1, UBound(arr, 2)) = Application.Index(arr, i, 0)
- End If
- Next
- End If
- End If
- Cells(n, 1).Resize(1, UBound(arr, 2)).Interior.ColorIndex = 4
- Next
- Application.ScreenUpdating = trus
- End Sub
复制代码
|
|