- 帖子
- 21
- 主題
- 8
- 精華
- 0
- 積分
- 35
- 點名
- 0
- 作業系統
- winXP
- 軟體版本
- 1.0
- 閱讀權限
- 10
- 性別
- 男
- 註冊時間
- 2010-8-4
- 最後登錄
- 2018-3-8

|
回復 2# GBKEE
謝謝您的回答 我剛試了一下 可以用 不過我發現有另一個問題
用個股代號、進場日期來排序
刪除列應該是2個條件
1. 當日與下一日 個股名稱一樣 & 出場日一樣
2. 個股名稱一樣 當日進場還沒出場 下一筆就進場 這是不對的 (我昨天忘了考慮到這個)
剛自己改了改 應該ok 只是程式寫的有點醜
還望請你指點一二
Sub Ex()
Dim i As Integer, Rng As Range
'With ActiveSheet 'Sheets("sheet1")
With Sheets("投資匯總表")
.UsedRange.Sort Key1:=.Range("A2"), Order1:=xlAscending, Key2:=.Range( _
"C2"), Order2:=xlAscending, Header:=xlYes
i = 2
Do While .Cells(i, "E") <> ""
If (.Cells(i, "b") & .Cells(i, "E") = .Cells(i + 1, "b") & .Cells(i + 1, "E")) Then
If Rng Is Nothing Then
Set Rng = .Cells(i, "E").Offset(1)
Else
Set Rng = Union(Rng, .Cells(i, "E").Offset(1))
End If
End If
i = i + 1
Loop
If Not Rng Is Nothing Then
Rng.EntireRow.Delete
' 我自己寫的 主要是處理考慮點2
i = 2
Do While .Cells(i, "E") <> ""
If .Cells(i, "b") = .Cells(i + 1, "b") Then
If .Cells(i, "E") > .Cells(i + 1, "C") Then
.Rows(i + 1).Delete Shift:=xlUp
i = i - 1
End If
End If
i = i + 1
Loop
.UsedRange.Sort Key1:=.Range("C2"), Order1:=xlAscending, Key2:=.Range( _
"A2"), Order2:=xlAscending, Header:=xlYes
End If
End With
End Sub |
|