|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim arr1, arr2, h%, arr, b As Boolean
- arr1 = Sheets("sheet1").Range("b2").Resize(Sheets("sheet1").Range("b65536").End(xlUp).Row - 1, 4)
- arr2 = Sheets("sheet1").Range("j2").Resize(Sheets("sheet1").Range("j65536").End(xlUp).Row - 1, 4)
- h = 2
- With Sheets("sheet3")
- .Range("a2:c65536").ClearContents
- For i = 1 To UBound(arr1)
- ReDim arr(1 To arr1(i, 2))
- For j = 1 To UBound(arr2)
- If arr2(j, 1) = arr1(i, 1) Then
- If arr2(j, 3) >= arr1(i, 3) And arr2(j, 3) <= arr1(i, 4) Then
- If arr2(j, 2) > arr1(i, 4) - arr2(j, 3) + 1 Then
- p = arr1(i, 4) - arr2(j, 3) + 1
- Else
- p = arr2(j, 2)
- End If
- For k = 1 To p
- arr(arr2(j, 3) - arr1(i, 3) + k) = 1
- Next k
- End If
- End If
-
- Next j
- b = False
- For l = 1 To UBound(arr)
- If arr(l) = 1 Then
- If b Then
- .Cells(h, 2) = Format(arr1(i, 3) + l - 2, "00000000")
- .Cells(h, 3) = .Cells(h, 2) - .Cells(h, 1) + 1
- h = h + 1
- End If
- b = False
-
- Else
-
- If Not b Then
- .Cells(h, 1) = Format(arr1(i, 3) + l - 1, "00000000")
- End If
- b = True
- End If
- Next l
- If b Then
- .Cells(h, 2) = Format(arr1(i, 3) + l - 2, "00000000")
- .Cells(h, 3) = .Cells(h, 2) - .Cells(h, 1) + 1
- h = h + 1
- End If
-
- Next i
- End With
- End Sub
复制代码 调试了好几次,比较绕人。
|
评分
-
1
查看全部评分
-
|