|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 对齐()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Dim rn As Range
Dim br()
Set d = CreateObject("scripting.dictionary")
With Sheets("原始")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(1, Columns.Count).End(xlToLeft).Column
If r < 2 Then MsgBox "原始表为空!": End
ar = .Range(.Cells(1, 1), .Cells(r, y))
Set rn = .Rows(1)
End With
With Sheets("实现效果")
.UsedRange = Empty
rn.Copy .[a1]
n = 1
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
n = n + 1
For j = 1 To 3
.Cells(n, j) = ar(i, j)
Next j
d(ar(i, 1)) = n
End If
Next i
For j = 4 To UBound(ar, 2) Step 3
For i = 2 To UBound(ar)
If ar(i, j) <> "" Then
xh = d(ar(i, j))
If xh <> "" Then
w = j - 1
For s = j To j + 2
w = w + 1
.Cells(xh, w) = ar(i, s)
Next s
End If
End If
Next i
k = .Cells(Rows.Count, j).End(xlUp).Row
For i = 2 To UBound(ar)
If ar(i, j) <> "" Then
xh = d(ar(i, j))
If xh = "" Then
k = k + 1
w = j - 1
For s = j To j + 2
w = w + 1
.Cells(k, w) = ar(i, s)
Next s
End If
End If
Next i
Next j
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
评分
-
1
查看全部评分
-
|