罫線ではなくて、コネクタで引く事例です。目的のシートのシートモジュールに記載して下さい。
TOの列に入力した際に、FROMの列に数値が入力されていれば、それぞれC列、A列から検索して結線します。
シートのイベントについては、参考URLなどをご覧下さい。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim fromCell As Range, toCell As Range
If Target.Cells.Count > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
If Intersect(Target, Range("$G:$G")) Is Nothing Then Exit Sub
If Target.Offset(0, -1).Value = "" Then Exit Sub
Set fromCell = Range("$A:$A").Find(Target.Offset(0, -1).Value, LookIn:=xlValue, LookAt:=xlWhole)
If fromCell Is Nothing Then Exit Sub
Set toCell = Range("$C:$C").Find(Target.Value, LookIn:=xlValue, LookAt:=xlWhole)
If toCell Is Nothing Then Exit Sub
connectCell fromCell, toCell
End Sub
Private Sub connectCell(myCell1 As Range, myCell2 As Range)
Dim rect1 As Shape, rect2 As Shape, connectLine As Shape
Set rect1 = drawRect(myCell1)
Set rect2 = drawRect(myCell2)
Set connectLine = ActiveSheet.Shapes.AddConnector(msoConnectorStraight, 0, 0, 1, 1)
With connectLine
.Line.Weight = 4.5
.Line.DashStyle = msoLineDash
.ConnectorFormat.BeginConnect rect1, 4
.ConnectorFormat.EndConnect rect2, 2
End With
rect1.Delete
rect2.Delete
End Sub
Private Function drawRect(myCell As Range) As Shape
With myCell
Set drawRect = ActiveSheet.Shapes.AddShape(msoShapeRectangle, .Left, .Top, .Width, .Height)
End With
End Function
お礼
参考になりました。 ありがとうございます。