懂得宏的高手请进

来源:百度知道 编辑:UC知道 时间:2024/06/06 04:16:00
代码我已经有了,怎么弄
Sub aaa()
Dim i, j, k, m As Integer
k = 6
j = 1
i = 1
m = ActiveSheet.UsedRange.Rows.Count
Columns("A:B").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
:=xlPinYin, DataOption1:=xlSortNormal

Cells(1, 4).Value = Cells(1, 1).Value
Cells(1, 5).Value = Cells(1, 2).Value
For i = 2 To m
If Cells(i, 1).Value = Cells(i - 1, 1).Value Then
Cells(j, k).Value = Cells(i, 2).Value
k = k + 1
Else:
j = j + 1
k = 5
Cells(j, 4).Value = Cells(i, 1).Value
Cells(j, 5).Value = Cells(i, 2).Value
k = k + 1
End If
Next
End Sub

在EXCEL界面,按下Alt + F11
接着双击左边的ThisWorkbook
出现一个代码窗口后,输入代码
按 Ctrl + S 保存,
按 F5 就能运行了。

在工具栏下的倒数第五个选项创建宏然后编辑应该上面的函数

操作excel?