|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
自适应代码。当然输入输出位置还是要指定。- Sub aa()
- Dim brr()
- arr = [a2:an2]
- maxi = arr(1, 1)
- mini = arr(1, 1)
- For i = 1 To UBound(arr, 2) Step 2
- If maxi < arr(1, i) Then maxi = arr(1, i)
- If mini > arr(1, i) Then mini = arr(1, i)
- Next
- ReDim brr(UBound(arr, 2) / 2, mini To maxi)
- For i = 1 To UBound(arr, 2) Step 2
- brr(0, arr(1, i)) = brr(0, arr(1, i)) + 1
- brr(brr(0, arr(1, i)), arr(1, i)) = arr(1, i + 1)
- Next
- ii = 0
- For i = 1 To UBound(brr, 1)
- For j = LBound(brr, 2) To UBound(brr, 2)
- If brr(0, j) > 0 Then
- arr(1, 2 * ii + 1) = j
- arr(1, 2 * ii + 2) = brr(i, j)
- ii = ii + 1
- brr(0, j) = brr(0, j) - 1
- End If
- Next
- Next
- [a5:an5] = arr
- End Sub
复制代码 |
|