Sub fyExcelVBA()
Dim arr, brr, crr, i%, j%
Dim m%, n%
Dim o, p, r, s As String
arr = Sheets("sheet11").Range("D8").CurrentRegion
ReDim brr(8 To UBound(arr), 1 To UBound(arr))
crr = brr
For i = 8 To UBound(arr)
If arr(i, 4) = "安装" Then
n = n + 1
brr(n, 1) = arr(i, 1)
brr(n, 2) = arr(i, 2)
brr(n, 5) = arr(i, 3)
brr(n, 6) = arr(i, 6)
r = Format(arr(i, 15), "#")
s = Format(arr(i, 16), "#")
crr(n, 7) = DateSerial(2018, r, s)
ElseIf arr(i, 4) = "维修" Then
m = m + 1
crr(m, 1) = arr(i, 1)
crr(m, 2) = arr(i, 2)
crr(m, 5) = arr(i, 3)
crr(m, 6) = arr(i, 6)
r = Format(arr(i, 15), "#")
s = Format(arr(i, 16), "#")
crr(n, 7) = DateSerial(2018, r, s)
End If
Next i
Sheets("安装").Range("a4").Resize(UBound(brr), UBound(brr, 2)).ClearContents
Sheets("安装").Range("a4").Resize(UBound(brr), UBound(brr, 2)) = brr
Sheets("维修").Range("a4").Resize(UBound(crr), UBound(crr, 2)).ClearContents
Sheets("维修").Range("a4").Resize(UBound(crr), UBound(crr, 2)) = crr
End Sub
这个代码运行的时候提示下标越界,该如何解决呢 |