|
彻底完成。增加了自动画线。- Private Sub Worksheet_Change(ByVal Target As Range)
- If Target.Address = "$A$1" Then
- If [a1] = 0 Then n = InputBox("", "", 11) Else n = [a1]
- [c3].Resize(n, n).Name = "Rng"
- Call kagawa(n)
- [a1].Activate
- End If
- End Sub
- Sub kagawa(n)
-
- For Each shp In ActiveSheet.Shapes
- shp.Delete
- Next
-
- [b2:iv256].Clear
- [c3].Resize(n, n) = 1
-
- '起点
- [b2].Offset(n).Activate
- ActiveCell.Interior.ColorIndex = 8
- ActiveCell = ChrW(8594)
- With ActiveSheet.Shapes.BuildFreeform(msoEditingAuto, ActiveCell.Left + ActiveCell.Width / 2, ActiveCell.Top + ActiveCell.Height / 2)
-
- '横線1(水平線1)
- For i = 1 To n + 1
- ActiveCell.Offset(, 1).Activate
- ActiveCell.Interior.ColorIndex = 6
- If ActiveCell = 1 Then ActiveCell = "*"
- Next
- ActiveCell = ChrW(8598)
- .AddNodes msoSegmentLine, msoEditingAuto, ActiveCell.Left + ActiveCell.Width / 2, ActiveCell.Top + ActiveCell.Height / 2
- k = k + 1
-
- '右斜線1
- For i = 1 To n
- ActiveCell.Offset(-1, -1).Activate
- ActiveCell.Interior.ColorIndex = 6
- If ActiveCell = 1 Then ActiveCell = "*"
- Next
- ActiveCell = ChrW(8595)
- .AddNodes msoSegmentLine, msoEditingAuto, ActiveCell.Left + ActiveCell.Width / 2, ActiveCell.Top + ActiveCell.Height / 2
- k = k + 1
-
-
- '縦線1(垂直線1)
- y = Round((2 * n - 4) / 3)
- t = Int((n - 1) / 3)
- For i = 1 To n + t
- ActiveCell.Offset(1).Activate
- ActiveCell.Interior.ColorIndex = 6
- If ActiveCell = 1 Then ActiveCell = "*" Else If ActiveCell = "" Then ActiveCell = ChrW(8595)
- Next
- ActiveCell = ChrW(8599)
- .AddNodes msoSegmentLine, msoEditingAuto, ActiveCell.Left + ActiveCell.Width / 2, ActiveCell.Top + ActiveCell.Height / 2
- k = k + 1
-
- '左斜線、横線、縦線 繰り返す
- For j = 1 To y
- '左斜線
- For i = 1 To n + t - j
- ActiveCell.Offset(-1, 1).Activate
- ActiveCell.Interior.ColorIndex = 6
- If ActiveCell = 1 Then ActiveCell = "*" Else If ActiveCell = "" Then ActiveCell = ChrW(8599)
- Next
- ActiveCell = ChrW(8592)
- .AddNodes msoSegmentLine, msoEditingAuto, ActiveCell.Left + ActiveCell.Width / 2, ActiveCell.Top + ActiveCell.Height / 2
- k = k + 1
- If Application.Sum(Range("Rng")) = 0 Then Exit For
-
- '左横線
- For i = 1 To n + t - j - 1
- ActiveCell.Offset(, -1).Activate
- ActiveCell.Interior.ColorIndex = 6
- If ActiveCell = 1 Then ActiveCell = "*" Else If ActiveCell = "" Then ActiveCell = ChrW(8592)
- Next
- .AddNodes msoSegmentLine, msoEditingAuto, ActiveCell.Left + ActiveCell.Width / 2, ActiveCell.Top + ActiveCell.Height / 2
- k = k + 1
-
- '下縦線
- For i = 1 To n + t - j
- ActiveCell.Offset(1).Activate
- ActiveCell.Interior.ColorIndex = 6
- If ActiveCell = 1 Then ActiveCell = "*" Else If ActiveCell = "" Then ActiveCell = ChrW(8595)
- Next
- ActiveCell = ChrW(8599)
- .AddNodes msoSegmentLine, msoEditingAuto, ActiveCell.Left + ActiveCell.Width / 2, ActiveCell.Top + ActiveCell.Height / 2
- k = k + 1
- If Application.Sum(Range("Rng")) = 0 Then Exit For
- Next
-
- ActiveCell.Interior.ColorIndex = 8
- ActiveCell = ChrW(9678)
- ActiveCell.CurrentRegion.HorizontalAlignment = xlCenter
- ActiveCell.CurrentRegion.VerticalAlignment = xlCenter
- .ConvertToShape.Select
- End With
- Selection.ShapeRange.Line.BeginArrowheadStyle = msoArrowheadDiamond
- Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadTriangle
-
- Application.StatusBar = n & "x" & n & " = " & k & " (t= " & t & ")"
-
- End Sub
复制代码 |
|