下面的VBA應該這樣做,你需要將它複製到Sheet1 (Main)
的工作簿代碼部分。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Sheet As Worksheet
Dim Index As Integer
Dim Count As Integer
Dim Match As Range
If Target.Rows.Count > 1 Or Target.Columns.Count > 1 Then
' You've done something that has edited lots of cells. Cant handle this.
Exit Sub
End If
Set Sheet = ThisWorkbook.Worksheets("Main")
If Not Intersect(Sheet.Range("D:D"), Target) Is Nothing Then
' The edited cell falls in the range D:D
Count = ThisWorkbook.Worksheets.Count
For Index = 1 To Count
If Not ThisWorkbook.Worksheets(Index).Name = Sheet.Name Then
Set Match = ThisWorkbook.Worksheets(Index).Range("D:D").Find(What:=Target.Value, LookIn:=xlValues)
If Not Match Is Nothing Then
'copy the line across
ThisWorkbook.Worksheets(Index).Range("A" & Match.Row & ":E" & Match.Row).Copy Sheet.Range("A" & Target.Row)
Exit For
End If
End If
Next Index
End If
If Match Is Nothing Then
' optional, if the target string is not found clear the line.
Sheet.Range("A" & Target.Row & ":E" & Target.Row).ClearContents
End If
End Sub
取決於在其他工作表中找到唯一代碼的難度,實現您的目標應該相當簡單。 – NickSlash 2013-03-13 23:45:25