下载附件,按键执行程序即可。
Sub 合并_Click()
a = Cells(Rows.Count, 1).End(3).Row
b = Cells(Rows.Count, 2).End(3).Row
Columns("C:C").Select
Selection.ClearContents
Cells(1, 3) = "合并两列"
Range(Cells(2, 1), Cells(a, 1)).Select
Selection.Copy
Cells(2, 3).Select
ActiveSheet.Paste
Range(Cells(2, 2), Cells(b, 2)).Select
Selection.Copy
Cells(a + 1, 3).Select
ActiveSheet.Paste
For i = 2 To a + b + 1
If WorksheetFunction.CountIf(Range(Cells(i, 3), Cells(a + b + 1, 3)), Cells(i, 3)) > 1 Then
Cells(i, 3) = ""
End If
Next
Range(Cells(2, 3), Cells(a + b + 1, 3)).Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("C2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range(Cells(2, 3), Cells(a + b + 1, 3))
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub