返回列表 上一主題 發帖

[發問] 救救我吧!日期複製(詳情請參閱內文)

本帖最後由 luhpro 於 2011-6-9 00:21 編輯

回復 1# emmalee
以下程式放在 Sheet2 內
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2.   Dim iRow%
  3.   
  4.   With Target
  5.     If .Column = 2 And .Row = 1 Then
  6.       Application.EnableEvents = False
  7.       With .Parent
  8.         iRow = .Cells(Rows.Count, 1).End(xlUp).Row
  9.         If iRow < 3 Then iRow = 3
  10.         .Range(.[A3], .Cells(iRow, 2)).Clear
  11.       End With
  12.       Call GetDate(Target)
  13.       Application.EnableEvents = True
  14.       Target.Select
  15.       
  16.     End If
  17.   End With
  18. End Sub
複製代碼
以下程式放在 Module 內
  1. Sub GetDate(ByVal rTar As Range)
  2.   Dim iRow%
  3.   Dim dDate As Date
  4.   Dim vSheet1, rFind As Range
  5.   
  6.   On Error Resume Next
  7.   Set vSheet1 = Sheets("Sheet1")
  8.   
  9.   With vSheet1
  10.     iRow = .Cells(Rows.Count, 1).End(xlUp).Row
  11.     Set rFind = Nothing
  12.     dDate = rTar.Value
  13.     Do Until rFind.Row > 1
  14.       Set rFind = Range(.[A2], .Cells(iRow, 1)).Find(dDate, LookIn:=xlValues)
  15.       dDate = dDate + 1
  16.     Loop
  17.       .Range(rFind, .Cells(iRow, 2)).Copy
  18.       rTar.Parent.[A3].PasteSpecial Paste:=xlPasteAll
  19.   End With
  20. End Sub
複製代碼

TOP

        靜思自在 : 一個人不怕錯,就怕不改過,改過並不難。
返回列表 上一主題