Private Sub Worksheet_Change(ByVal Target As Range)
Dim xF As Range, xE As Range
With Target
If .Address <> "$A$2" Then Exit Sub
If .Value = "" Then Exit Sub
Set xF = [Sheet1!A:A].Find(.Value, Lookat:=xlWhole)
If xF Is Nothing Then MsgBox "無此資料": GoTo 999 '找不到,跳至〔標記999〕,並結束執行
Set xE = Cells(Rows.Count, "B").End(xlUp)(2) 'B欄最後一筆資料的下一空白格
Application.EnableEvents = False
xF.Resize(1, 7).Copy xE '複製內容(含格式)
xE = xE.Row - 1 '〔序號〕以〔列號〕減1
End With 999:
Target.Select
Application.EnableEvents = True
End Sub
以下兩行意思一樣:
Set xE = Cells(Rows.Count, "B").End(xlUp)(2)
Set xE = Cells(Rows.Count, "B").End(xlUp).Cells(2, 1)作者: regedit77 時間: 2015-11-23 08:03