- 帖子
- 835
- 主題
- 6
- 精華
- 0
- 積分
- 915
- 點名
- 0
- 作業系統
- Win 10,7
- 軟體版本
- 2019,2013,2003
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2010-5-3
- 最後登錄
- 2024-11-14
|
3#
發表於 2011-6-9 00:20
| 只看該作者
本帖最後由 luhpro 於 2011-6-9 00:21 編輯
回復 1# emmalee
以下程式放在 Sheet2 內- Private Sub Worksheet_Change(ByVal Target As Range)
- Dim iRow%
-
- With Target
- If .Column = 2 And .Row = 1 Then
- Application.EnableEvents = False
- With .Parent
- iRow = .Cells(Rows.Count, 1).End(xlUp).Row
- If iRow < 3 Then iRow = 3
- .Range(.[A3], .Cells(iRow, 2)).Clear
- End With
- Call GetDate(Target)
- Application.EnableEvents = True
- Target.Select
-
- End If
- End With
- End Sub
複製代碼 以下程式放在 Module 內- Sub GetDate(ByVal rTar As Range)
- Dim iRow%
- Dim dDate As Date
- Dim vSheet1, rFind As Range
-
- On Error Resume Next
- Set vSheet1 = Sheets("Sheet1")
-
- With vSheet1
- iRow = .Cells(Rows.Count, 1).End(xlUp).Row
- Set rFind = Nothing
- dDate = rTar.Value
- Do Until rFind.Row > 1
- Set rFind = Range(.[A2], .Cells(iRow, 1)).Find(dDate, LookIn:=xlValues)
- dDate = dDate + 1
- Loop
- .Range(rFind, .Cells(iRow, 2)).Copy
- rTar.Parent.[A3].PasteSpecial Paste:=xlPasteAll
- End With
- End Sub
複製代碼 |
|