Private Sub CommandButton2_Click()
Dim wL As Shape, c1 As Range, cell1 As String, cell2 As String
Dim x1 As Double, y1 As Double, x2 As Double, y2 As Double
Dim wTotal As Double, wPoint As Double, wInter As Double
Dim alto As Double
On Error Resume Next
On Error GoTo 0
Set c1 = Range("A:A").Find(Range("AJ1").Value, LookIn:=xlValues, lookat:=xlWhole)
If Not c1 Is Nothing Then
cell1 = c1.Address
Set c1 = Range("A:A").Find(Range("AJ2").Value, LookIn:=xlValues, lookat:=xlWhole)
If Not c1 Is Nothing Then
cell2 = c1.Address
x1 = Range(cell1).Left + Range(cell1).Width / 2
y1 = Range(cell1).Top + Range(cell1).Height
x2 = x1
y2 = Range(cell2).Top
wTotal = Range("AJ1") + Range("AJ2")
wPoint = Range("AK1").Value / wTotal
wInter = (y2 + y1) * wPoint
Set wL = ActiveSheet.Shapes.AddConnector(msoConnectorStraight, x1, y1, x2, y2)
wL.Line.Weight = 1
wL.Line.ForeColor.RGB = RGB(0, 0, 0)
wL.Name = "Line1"
Set wL = ActiveSheet.Shapes.AddConnector(msoConnectorStraight, x1, wInter, x1 + 20, wInter)
wL.Line.Weight = 1
wL.Line.ForeColor.RGB = RGB(0, 0, 0)
wL.Name = "Line2"
alto = (wInter - y1) - 6
Set wL = ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, x1 + 3, y1 + 3, 290, alto)
wL.TextFrame.Characters.Text = "LAYER 2"
wL.ScaleHeight 0.1595115118, msoFalse, _
msoScaleFromBottomRight
wL.Name = "Line3"
Set c1 = Range("A:A").Find(Range("AF1").Value, LookIn:=xlValues, lookat:=xlWhole)
If Not c1 Is Nothing Then
cell1 = c1.Address
Set c1 = Range("A:A").Find(Range("AF2").Value, LookIn:=xlValues, lookat:=xlWhole)
If Not c1 Is Nothing Then
cell2 = c1.Address
x1 = Range(cell1).Left + Range(cell1).Width / 2
y1 = Range(cell1).Top + Range(cell1).Height
x2 = x1
y2 = Range(cell2).Top
wTotal = Range("AF1") + Range("AF2")
wPoint = Range("AG1").Value / wTotal
wInter = (y2 + y1) * wPoint
Set wL = ActiveSheet.Shapes.AddConnector(msoConnectorStraight, x1, y1, x2, y2)
wL.Line.Weight = 1
wL.Line.ForeColor.RGB = RGB(0, 0, 0)
wL.Name = "Line1"
Set wL = ActiveSheet.Shapes.AddConnector(msoConnectorStraight, x1, wInter, x1 + 20, wInter)
wL.Line.Weight = 1
wL.Line.ForeColor.RGB = RGB(0, 0, 0)
wL.Name = "Line2"
alto = (wInter - y1) - 6
Set wL = ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, x1 + 3, y1 + 3, 290, alto)
wL.TextFrame.Characters.Text = "LAYER 1"
wL.Name = "Line3"
End If
End If
End If
End If
End Sub