COL 1 COL 2
A E
B G
C A
G A
D C
E F
D F
F F
我希望它看起来像:
COL 1 COL 2
A A
BLANK A
B BLANK
C C
D BLANK
D BLANK
E E
F F
BLANK F
BLANK F
G G
请帮帮我。我在两列中有大量数字,我想将它们对齐,如上所示。
答案1
这似乎正确地重新组织了您提供的样本数据。
Sub mcr_fix()
Dim rw As Long, c As Long
With ActiveSheet
For c = 1 To 2
With .Cells(1, 1).CurrentRegion.Columns(c)
.Cells.Sort key1:=.Columns(1), order1:=xlAscending, _
Orientation:=xlTopToBottom, Header:=xlYes
End With
Next c
rw = 3
Do While CBool(Application.CountA(.Cells(rw, 1).Resize(1, 2)))
If .Cells(rw, 1).Value > .Cells(rw, 2).Value Then
.Cells(rw, 1).Insert Shift:=xlDown
ElseIf .Cells(rw, 1).Value < .Cells(rw, 2).Value Then
.Cells(rw, 2).Insert Shift:=xlDown
End If
rw = rw + 1
If rw > 500 Then Exit Do
Loop
End With
End Sub