I'm trying to create a VBA script that compares two similar ranges of cells and draws arrows between cells with matching text strings. Think of making a seating chart of names in excel where you want to visually show the necessary moves from one seating chart to the next. I have that working successfully in the script shown in this post which I've pulled together from various scripts posted on the web.
My issue is that I don't want to draw an arrow in the case where the cells match but the relative position in the range doesn't change. Or in other words, for the person who stays in the same seat from one seating chart to the next, I don't want to draw the arrow between those cells.
I'm hoping this just means adding another condition argument but I don't know how to write it.
Any help?
My issue is that I don't want to draw an arrow in the case where the cells match but the relative position in the range doesn't change. Or in other words, for the person who stays in the same seat from one seating chart to the next, I don't want to draw the arrow between those cells.
I'm hoping this just means adding another condition argument but I don't know how to write it.
Any help?
Code:
Sub DrawArrows12()
Dim Rng As Range, Dn As Range
Set Rng = Range(Range("C2"), Range("G16"))
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Each Dn In Rng
If Not IsNumeric(Dn) Then
If Not .Exists(Dn.Value) Then
.Add Dn.Value, Dn
Else
ActiveSheet.Shapes.AddConnector(msoConnectorStraight, Dn.Left + (Dn.Width / 2), Dn.Top, .Item(Dn.Value).Left + (.Item(Dn.Value).Width / 2), .Item(Dn.Value).Top + (.Item(Dn.Value).Height)).Select
With Selection.ShapeRange.Line
.BeginArrowheadStyle = msoArrowheadOpen
.EndArrowheadStyle = msoArrowheadOval
.Weight = 1.75
.Transparency = 0.7
If UCase(LineType) = "DOUBLE" Then 'double arrows
.BeginArrowheadStyle = msoArrowheadOpen
ElseIf UCase(LineType) = "LINE" Then 'Line (no arrows)
.EndArrowheadStyle = msoArrowheadNone
Else 'single arrow
'defaults to an arrow with one head
End If
'color arrow
If RGBcolor <> 0 Then
.ForeColor.RGB = RGBcolor 'custom color
Else
.ForeColor.RGB = RGB(228, 108, 10) 'orange (DEFAULT)
End If
End With
End If
End If
Next
End With
End Sub