2009年6月16日星期二

EXCELVBA - 刪除相同列_留最大值

Sub 刪除相同列_留最大值()
'取列
i = 1

Range("B2").Select
Selection.End(xlDown).Select
x = ActiveCell.Row
rx = "a1:y" & x
'排序

Range(rx).Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range( _
"A2"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase _
:=False, Orientation:=xlTopToBottom, SortMethod:=xlStroke, DataOption1:= _
xlSortNormal, DataOption2:=xlSortNormal
Range("B2").Select

While (i <> x)


If ActiveCell.Value = ActiveCell.Offset(1, 0).Value Then

y = ActiveCell.Row
ry = y & ":" & y
Rows(ry).Select
Selection.Delete Shift:=xlUp
rb = "b" & y
Range(rb).Select
Else
ActiveCell.Offset(1, 0).Select



End If

i = i + 1
Wend



End Sub

0 评论:

 
妹咕數位學園歡迎網友們來信指教 妹咕信箱