Generering af bankoplader
Har fundet denne kode her på eksperten, men kan ikke finde hoved eller hale i den :-)Kan nogen hjælpe, så der kan være 6 plader på et A4-ark (liggende).
Option Base 1
Dim PladeTal As Byte
Dim Plade() As Byte
Sub BingoPlader()
Dim i As Byte
Cells.Delete
For i = 0 To InputBox("Hvor mange plader", "Bingo plader")
Call GenPlade(i * 7 + 1, 1)
Next i
End Sub
Sub GenPlade(ByVal Xoff, Yoff As Integer)
Dim i, j As Byte
ReDim Plade(9, 4) As Byte
Randomize
Call FormatPlade(Xoff, Yoff)
For j = 1 To 3
i = 1
While i <= 5
PladeTal = CByte(Rnd() * 90) + 1
If PullNum(j) Then i = i + 1
Wend
Next j
Call SortPlade
Call PrintPlade(Xoff, Yoff)
End Sub
Sub FormatPlade(ByVal Xoff, Yoff As Integer)
Const KantFarve = 40
Const BagFarve = 2
Const StorTekst = 24
Const LilleTekst = 10
Columns("B:J").ColumnWidth = 8
Range("A:A,K:K").ColumnWidth = 2
Rows("1:1").RowHeight = 12
Range("A1:K5").Offset(Xoff - 1, Yoff - 1).Interior.ColorIndex = KantFarve
With Range("A1:I3").Offset(Xoff, Yoff)
.Interior.ColorIndex = BagFarve
.ClearContents
.Font.Size = StorTekst
.RowHeight = 55
.Borders.LineStyle = xlContinuous
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End Sub
Function PullNum(ByVal r As Byte) As Boolean
Select Case PladeTal
Case 1 To 9: If InsertNum(1, PladeTal, r) Then PullNum = True
Case 10 To 19: If InsertNum(2, PladeTal, r) Then PullNum = True
Case 20 To 29: If InsertNum(3, PladeTal, r) Then PullNum = True
Case 30 To 39: If InsertNum(4, PladeTal, r) Then PullNum = True
Case 40 To 49: If InsertNum(5, PladeTal, r) Then PullNum = True
Case 50 To 59: If InsertNum(6, PladeTal, r) Then PullNum = True
Case 60 To 69: If InsertNum(7, PladeTal, r) Then PullNum = True
Case 70 To 79: If InsertNum(8, PladeTal, r) Then PullNum = True
Case 80 To 90: If InsertNum(9, PladeTal, r) Then PullNum = True
Case Else: PullNum = False
End Select
End Function
Function InsertNum(ByVal Kol, tal, r As Byte) As Boolean
Dim n As Byte
Dim z As Boolean
z = False
If r = 3 Then
For n = 1 To 9
If CInt(Plade(n, 1)) + Plade(n, 2) + Plade(n, 3) = 0 Then
If n <> Kol Then
insernum = False
Exit Function
Else
Exit For
End If
End If
Next n
End If
If Plade(Kol, r) <> 0 Or Plade(Kol, 1) = tal Or Plade(Kol, 2) = tal Or Plade(Kol, 3) = tal Then
InsertNum = False
Else
Plade(Kol, r) = tal
InsertNum = True
End If
End Function
Sub PrintPlade(ByVal x, y As Integer)
Dim i, j As Byte
For i = 1 To 9
For j = 1 To 3
If Plade(i, j) <> 0 Then Cells(x + j, y + i) = Plade(i, j)
Next j
Next i
End Sub
Sub SortPlade()
Dim n, m, c, t As Byte
For n = 1 To 9
For m = 1 To 2
For c = m To 3
If Plade(n, m) > Plade(n, c) And Plade(n, m) > 0 And Plade(n, c) > 0 Then
t = Plade(n, m)
Plade(n, m) = Plade(n, c)
Plade(n, c) = t
End If
Next c
Next m
Next n
End Sub
På forhånd tak.
