|
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 2 Then Exit Sub
If Target = "" Then Exit Sub
If Target.Rows.Count > 1 Then Exit Sub
Dim rng As Range
With Sheet2
Set rng = .Columns(1).Find(Target.Value, lookat:=xlWhole)
If Not rng Is Nothing Then
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
If shp.TopLeftCell.Address = Target.Offset(0, 2).Address Then
shp.Delete
End If
Next
.Cells(rng.Row, 2).Copy Target.Offset(0, 2)
Target.Offset(0, 2).Borders.LineStyle = 1
For Each shp In ActiveSheet.Shapes
If shp.TopLeftCell.Address = Target.Offset(0, 2).Address Then
shp.Select
End If
Next
With Selection.ShapeRange
.LockAspectRatio = msoFalse
.Left = Target.Offset(0, 2).Left + 2
.Top = Target.Offset(0, 2).Top + 2
.Width = Target.Offset(0, 2).Width - 4
.Height = Target.Offset(0, 2).Height - 4
End With
End If
End With
End Sub
|
|