- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
4#
發表於 2014-2-12 07:35
| 只看該作者
回復 3# kasl - Option Explicit
- Sub Ex()
- Dim i As Integer, Rng As Range
- With ActiveSheet 'Sheets("sheet1")
- .UsedRange.Sort Key1:=.Range("A2"), Order1:=xlAscending, Key2:=.Range( _
- "E2"), Order2:=xlAscending, Header:=xlYes
- i = 2
- Do While .Cells(i, "E") <> ""
- If .Cells(i, "b") = .Cells(i + 1, "b") Then '當日與下一日 個股名稱一樣
- If .Cells(i, "E") = .Cells(i + 1, "E") Or .Cells(i, "E") > .Cells(i + 1, "C") Then
- '.Cells(i, "E") = .Cells(i + 1, "E")-> 出場日一樣
- '.Cells(i, "E") > .Cells(i + 1, "C")-> 當日進場還沒出場 下一筆就進場
- 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
- End If
- i = i + 1
- Loop
- If Not Rng Is Nothing Then
- Rng.EntireRow.Delete
- .UsedRange.Sort Key1:=.Range("C2"), Order1:=xlAscending, Key2:=.Range( _
- "A2"), Order2:=xlAscending, Header:=xlYes
- End If
- End With
- End Sub
複製代碼 |
|