過去ログ

???
エクセルのマクロ。実際に正方形を図示します。
Option Explicit
Sub Macro1()
Columns("B:J").Select
Range("B2298").Activate
Selection.ColumnWidth = 1.7
Cells(1, 1).Value = 0
Dim Ax As Integer
Dim Ay As Integer
Dim Bx As Integer
Dim By As Integer
Dim Cx As Integer
Dim Cy As Integer
Dim Dx As Integer
Dim Dy As Integer
Dim gyou As Integer
For Ax = 1 To 8
For Ay = 1 To 9
For Bx = Ax + 1 To 9
For By = Ay To 9
Cx = Bx - (By - Ay)
Cy = By + (Bx - Ax)
Dx = Ax - (By - Ay)
Dy = Ay + (Bx - Ax)
If Abs(Cx - 5) <= 4 And Abs(Cy - 5) <= 4 And Abs(Dx - 5) <= 4 And Abs(Dy - 5) <= 4 Then
Cells(1, 1).Value = Cells(1, 1).Value + 1
gyou = Cells(1, 1).Value * 10 - 9
Call keisen(gyou)
Cells(Ay + gyou - 1, Ax + 1).Value = "A"
Cells(By + gyou - 1, Bx + 1).Value = "B"
Cells(Cy + gyou - 1, Cx + 1).Value = "C"
Cells(Dy + gyou - 1, Dx + 1).Value = "D"
End If
Next By
Next Bx
Next Ay
Next Ax
Range("A1").Select
End Sub
Sub keisen(ByVal x As Integer)
Range("B" & strr(x) & ":J" & strr(x + 8)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
Private Function strr(ByVal x As Integer) As String
strr = Right(Str(x), Len(Str(x)) - 1)
End Function
   7月26日(木) 13:31:41     39638

過去問題一覧へ戻る