Sub Makro1()
' При заданных 1-5 ограничениях найти мин/мах  ЦФ F = x + y
 
        ' Данные (отсекаемые отрезки по осям) ЦФ и областей ограничений
     a = 111
     b = 111
 
     a1 = 30   ' 1
     b1 = 20
 
     a2 = 15  ' 2
     b2 = 40
 
     a3 = 40  ' 3
     b3 = 5
 
     a4 = 100   ' 4
     b4 = 80
 
     a5 = 80   ' 5
     b5 = 95
 
    Setka  ' выводим сетку для рисования

     '  Начала системы координат
   Dim xc, yc, Ms

   '  размер поля:  7.2, 4.8, 454.8, 736.8)
   Mash = 1 ' масштаб чертежа
   Ms = Mash * (730 / 297)
   xcc = 115 ' начала СК х
   ycc = 290 ' начала СК y
   ' Изображаем оси
    ActiveSheet.Shapes.AddLine(xcc, ycc, xcc + 300, ycc).Select ' ось х
    ActiveSheet.Shapes.AddLine(xcc, ycc, xcc, ycc - 300).Select ' ось z
    ActiveSheet.Shapes.AddLabel(msoTextOrientationHorizontal, xcc + 300, ycc, 0#, 0#).Select
    Selection.Characters.Text = "x"
    ActiveSheet.Shapes.AddLabel(msoTextOrientationHorizontal, xcc, ycc - 300, 0#, 0#).Select
    Selection.Characters.Text = "y"
    ' Изображаем ЦФ и ограничения в виде отрезков
    Otrezok a * Ms, 0, 0, b * Ms, xcc, ycc
    Otrezok a1 * Ms, 0, 0, b1 * Ms, xcc, ycc
    Otrezok a2 * Ms, 0, 0, b2 * Ms, xcc, ycc
    Otrezok a3 * Ms, 0, 0, b3 * Ms, xcc, ycc
    Otrezok a4 * Ms, 0, 0, b4 * Ms, xcc, ycc
    Otrezok a5 * Ms, 0, 0, b5 * Ms, xcc, ycc
 
    ' Обозначаем ЦФ и ограничения  точками на той или иной оси и номерами
    Point a * Ms, 0, xcc, ycc, 0
    Point 0 * Ms, b1 * Ms, xcc, ycc, 1
    Point a2 * Ms, 0, xcc, ycc, 2
    Point a3 * Ms, 0, xcc, ycc, 3
    Point a4 * Ms, 0, xcc, ycc, 4
    Point a5 * Ms, 0, xcc, ycc, 5
 
    ' Ищем точки пересечения только на многограннике ограничений при x,y > 0
 
    PerOtrxyS a1, 0, 0, b1, a2, 0, 0, b2, x12, y12
    Point2 x12 * Ms, y12 * Ms, xcc, ycc, 12
 
   PerOtrxyS a1, 0, 0, b1, a3, 0, 0, b3, x13, y13
    Point2 x13 * Ms, y13 * Ms, xcc, ycc, 13

   PerOtrxyS a4, 0, 0, b4, a5, 0, 0, b5, x45, y45
    Point2 x45 * Ms, y45 * Ms, xcc, ycc, 45
 
    ' Определяем точки и расстояние от точек пересечения до ЦФ
 
    PointPointSlineScript a, 0, 0, b, x12, y12, xc12, yc12
    Point2 xc12 * Ms, yc12 * Ms, xcc, ycc, 121
    Otrezok x12 * Ms, y12 * Ms, xc12 * Ms, yc12 * Ms, xcc, ycc
 
    PointPointSlineScript a, 0, 0, b, x13, y13, xc13, yc13
    Point2 xc13 * Ms, yc13 * Ms, xcc, ycc, 131
    Otrezok x13 * Ms, y13 * Ms, xc13 * Ms, yc13 * Ms, xcc, ycc
 
    PointPointSlineScript a, 0, 0, b, x45, y45, xc45, yc45
    Point2 xc45 * Ms, yc45 * Ms, xcc, ycc, 451
    Otrezok x45 * Ms, y45 * Ms, xc45 * Ms, yc45 * Ms, xcc, ycc
 
    ' Вычисляем длины от точек пересечения до ЦФ
 
    s1 = Sqr((x12 - xc12) * (x12 - xc12) + (y12 - yc12) * (y12 - yc12))
    s2 = Sqr((x13 - xc13) * (x13 - xc13) + (y13 - yc13) * (y13 - yc13))
    s3 = Sqr((x45 - xc45) * (x45 - xc45) + (y45 - yc45) * (y45 - yc45))
    MsgBox ("s1 = smax = " & s1)
    MsgBox ("s2 = " & s2)
    MsgBox ("s3 = smin = " & s3)
 
    ' Вычисляем знечения ЦФ  F = x + y
 
    MsgBox ("F1 = Fmin = " & x12 + y12)
    MsgBox ("F2 = " & x13 + y13)
    MsgBox ("F3 = Fmax = " & x45 + y45)
End Sub

Function Setka()
 s = 2 * 0.82
    Columns("A:A").ColumnWidth = s
    Columns("B:B").ColumnWidth = s
    Columns("C:C").ColumnWidth = s
    Columns("D:D").ColumnWidth = s
    Columns("E:E").ColumnWidth = s
    Columns("F:F").ColumnWidth = s
    Columns("G:G").ColumnWidth = s
    Columns("H:H").ColumnWidth = s
    Columns("I:I").ColumnWidth = s
    Columns("J:J").ColumnWidth = s
    Columns("K:K").ColumnWidth = s
    Columns("L:L").ColumnWidth = s
    Columns("M:M").ColumnWidth = s
    Columns("N:N").ColumnWidth = s
    Columns("O:O").ColumnWidth = s
    Columns("P:P").ColumnWidth = s
    Columns("Q:Q").ColumnWidth = s
    Columns("R:R").ColumnWidth = s
    Columns("S:S").ColumnWidth = s
    Columns("T:T").ColumnWidth = s
    Columns("U:U").ColumnWidth = s
    Columns("V:V").ColumnWidth = s
    Columns("W:W").ColumnWidth = s
    Columns("X:X").ColumnWidth = s
    Columns("Y:Y").ColumnWidth = s
    Columns("Z:Z").ColumnWidth = s
    Columns("AA:AA").ColumnWidth = s
    Columns("AB:AB").ColumnWidth = s
    Columns("AC:AC").ColumnWidth = s
    Columns("AH:AH").ColumnWidth = s
    Columns("AD:AD").ColumnWidth = s
    Columns("AE:AE").ColumnWidth = s
    Columns("AF:AF").ColumnWidth = s
    Columns("AI:AI").ColumnWidth = s
    Columns("AK:AK").ColumnWidth = s
    Columns("AG:AG").ColumnWidth = s
    Columns("AL:AL").ColumnWidth = s
    Columns("AJ:AJ").ColumnWidth = s
    Columns("AD:AD").ColumnWidth = s
    Columns("AE:AE").ColumnWidth = s
    Columns("AF:AF").ColumnWidth = s
    Columns("AI:AI").ColumnWidth = s
    Columns("AK:AK").ColumnWidth = s
    Columns("AG:AG").ColumnWidth = s
    Columns("AL:AL").ColumnWidth = s
    Columns("AJ:AJ").ColumnWidth = s
    End Function
 
Function Otrezok(x1, y1, x2, y2, xc, yc)
 
     Ax = xc + x1
     Ay = yc - y1

     Bx = xc + x2
     By = yc - y2
 
    ActiveSheet.Shapes.AddLine(Ax, Ay, Bx, By).Select
End Function
 

Function Point(x, y, xc, yc, ci)
 
    If x = "" Then x = 0
    If y = "" Then y = 0
    If z = "" Then z = 0
 
     Ax = xc + x
     Ay = yc - y
 
     ' MsgBox ("A1x = " & A1x)
    ActiveSheet.Shapes.AddShape(msoShapeOval, Ax - 3, Ay - 3, 6#, 6#).Select
    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 11 ' 53
 
    ActiveSheet.Shapes.AddLabel(msoTextOrientationHorizontal, Ax, Ay, 0#, 0#).Select
    Selection.Characters.Text = ci
End Function

Function PerOtrxyS(x1, y1, x2, y2, x3, y3, x4, y4, x, y)
    Mash = 1 ' масштаб чертежа
    Ms = Mash * (730 / 297)
'    MsgBox ("x1 = " & x1)
    s11 = y4 - y3
    s12 = x3 - x4
    s13 = (x3 * y3 - x3 * y4) * 1 + (y3 * x4 - y3 * x3)
    s = (-s11 * x1 - s12 * y1 - s13) / (s11 * (x2 - x1) + s12 * (y2 - y1))
    x = (1 - s) * x1 * 1 + s * x2 * 1
    y = (1 - s) * y1 * 1 + s * y2 * 1
 
End Function
 

Function Point2(x, y, xc, yc, ci)
 
    If x = "" Then x = 0
    If y = "" Then y = 0
    If z = "" Then z = 0
 
     Ax = xc + x
     Ay = yc - y
 
    ActiveSheet.Shapes.AddShape(msoShapeOval, Ax - 3, Ay - 3, 6#, 6#).Select
    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 53
 
    ActiveSheet.Shapes.AddLabel(msoTextOrientationHorizontal, Ax, Ay, 0#, 0#).Select
    Selection.Characters.Text = ci
End Function

Function PointPointSlineScript(x1, y1, x2, y2, x3, y3, xd, yd)
 
     td = ((x2 - x1) * (x3 - x1) + (y2 - y1) * (y3 - y1)) / ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
 
     xd = (x2 - x1) * td * 1 + x1 * 1
     yd = (y2 - y1) * td * 1 + y1 * 1
 
End Function