Dim Nmax As Integer ' max rows
Dim ModDivide As Long ' The divisor to return nCr mod
Dim ColorOffset As Integer
Dim ColorBackground As Integer
Dim NcCol As Integer ' N umber of c entral Col umn
Dim Coli As Integer ' the current color index
Sub TidyIt()
'Get Values
' put in four spin buttons max 49 min 2
'link these to cells b1,b2,b3,b4
' have a checkbox1 as triangle or square
Nmax = Cells(1, 2) ' max from <50
ModDivide = Cells(2, 2) ' to modular divide nCr
ColorOffset = Cells(3, 2) ' Color index start
ColorBackground = Cells(4, 2) ' background color
NoClear = Range("a1:b20")
Cells.Clear
Range("a1:b20") = NoClear
Columns.ColumnWidth = 30 / Nmax
Rows.RowHeight = 240 / Nmax
Columns("a:c").ColumnWidth = 8
Rows("1:4").RowHeight = 14
Range(Cells(4, 4), Cells(4 + 2 * Nmax, 4 + 2 * Nmax)) _
.Interior.ColorIndex = ColorBackground
End Sub
Sub ColMod()
Dim kk As Currency ' more accurate but still suspect nMax >45
Dim DivRem As Integer ' remainder after division
TidyIt
If CheckBox1.Value Then ' triangle or square
NcRow = 4
Else
NcRow = 4 + Nmax
End If
NcCol = Nmax + 4 ' num of column working about
For n = 1 To Nmax ' loop the number from -> rows
For m = -n + 2 To n - 2 Step 2
r = (m + n) / 2 'loop the size of group - > columns
kk = Application.WorksheetFunction.Combin(n, r)
DivRem = Round(kk - Int(kk / ModDivide) * ModDivide)
If DivRem > ModDivide Then DivRem = 0
' errors where n >45 and nCr very big
' non pattern colored cells in central columns
Coli = (DivRem + ColorOffset) Mod 55 + 1
Cells(NcRow + n - 1, NcCol + m).Interior.ColorIndex = Coli 'bot
If Not CheckBox1.Value Then ' place copies of triangle
Cells(NcCol + m, NcRow + n - 1).Interior.ColorIndex = Coli 'left
Cells(NcRow - n + 1, NcCol + m).Interior.ColorIndex = Coli 'top
Cells(NcRow + m, NcCol - n + 1).Interior.ColorIndex = Coli 'right
End If
Next m
Next n
End Sub
Private Sub SpinButton1_Change()
ColMod
End Sub
Private Sub SpinButton2_Change()
ColMod
End Sub
Private Sub SpinButton3_Change()
ColMod
End Sub
Private Sub SpinButton4_Change()
ColMod
End Sub