|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
请测试:
Sub Macro1()
Dim arr, brr(), d As Object, ds As Object, i&, j%, temp%, lr%
arr = Range("N1:Y6")
Set d = CreateObject("scripting.dictionary")
Set ds = CreateObject("scripting.dictionary")
For j = 1 To UBound(arr, 2)
Set d(j) = CreateObject("scripting.dictionary")
Next
For i = 2 To UBound(arr)
For j = 1 To UBound(arr, 2)
If Len(arr(i, j)) Then d(j)(arr(i, j)) = "" '不计“空白”
Next
Next
arr = Range("A2:L" & Range("A65536").End(xlUp).Row)
ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
For j = 1 To UBound(arr, 2)
For i = 1 To UBound(arr)
arr(i, j) = Format(arr(i, j), "00")
temp = Val(Left(arr(i, j), 1)) + Val(Right(arr(i, j), 1))
If d(j).Exists(temp) Then
ds(j) = ds(j) + 1
brr(ds(j), j) = arr(i, j)
ElseIf d(j).Exists(Val(Right(temp, 1))) Then '取个位数
ds(j) = ds(j) + 1
brr(ds(j), j) = arr(i, j)
End If
Next
If ds(j) > lr Then lr = ds(j)
Next
Range("N7:Y" & ActiveSheet.UsedRange.Rows.Count).ClearContents
With Range("N7").Resize(lr, UBound(arr, 2))
.Value = brr
.NumberFormatLocal = "00"
End With
End Sub |
|