Bekijk de onderstaande video om te zien hoe je onze site als een web app op je startscherm installeert.
Opmerking: Deze functie is mogelijk niet beschikbaar in sommige browsers.
Privacywetgeving
Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.
Sub FillCells()
On Error GoTo errlog
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
.DisplayAlerts = False
End With
Columns("B:G").ClearContents
Set Rng = Cells(5, 1).CurrentRegion
mx = WorksheetFunction.Max(Rng.Columns(1))
rw = Rng.Rows.Count
tmp = 0
nLoop = 100
For Each c In Rng.Columns(1).Cells
If c = "Vrij" Or c < 1 Then GoTo nxt
CntLoop = 0
While CntLoop < nLoop
CntLoop = CntLoop + 1
tmp1 = Int((rw * Rnd(1)) + 1)
If Rng.Cells(tmp1, 1) = "Vrij" Then
GoTo col2
End If
If Rng.Cells(tmp1, 5) = "" Then
If Rng.Cells(tmp1, 1) = c.Offset(-1, 2) Or _
Rng.Cells(tmp1, 1) = c.Offset(0, 0) Then
GoTo col2
Else
c.Offset(0, 1) = Rng.Cells(tmp1, 1)
Rng.Cells(tmp1, 5) = "x"
GoTo nxtcol3
End If
Else
GoTo col2
End If
col2:
Wend
If CntLoop = nLoop Then
c.Offset(0, 1) = 1
End If
nxtcol3:
CntLoop = 0
While CntLoop < nLoop
CntLoop = CntLoop + 1
tmp1 = Int((rw * Rnd(1)) + 1)
If Rng.Cells(tmp1, 1) = "Vrij" Then
GoTo col3
End If
If Rng.Cells(tmp1, 6) = "" Then
If Rng.Cells(tmp1, 1) = c.Offset(-1, 2) Or _
Rng.Cells(tmp1, 1) = c.Offset(0, 1) Then
GoTo col3
Else
c.Offset(0, 2) = Rng.Cells(tmp1, 1)
Rng.Cells(tmp1, 6) = "x"
GoTo nxtcol4
End If
Else
GoTo col3
End If
col3:
Wend
If CntLoop = nLoop Then
c.Offset(0, 2) = Rng.Cells(tmp1, 1)
End If
nxtcol4:
CntLoop = 0
While CntLoop < nLoop
CntLoop = CntLoop + 1
tmp1 = Int((rw * Rnd(1)) + 1)
If Rng.Cells(tmp1, 1) = "Vrij" Then
GoTo col4
End If
If Rng.Cells(tmp1, 7) = "" Then
If Rng.Cells(tmp1, 1) = c.Offset(-1, 3) Or _
Rng.Cells(tmp1, 1) = c.Offset(0, 2) Then
GoTo col4
Else
c.Offset(0, 3) = Rng.Cells(tmp1, 1)
Rng.Cells(tmp1, 7) = "x"
GoTo nxt
End If
Else
GoTo col4
End If
col4:
Wend
If CntLoop = nLoop Then
c.Offset(0, 3) = 1
End If
nxt:
Next
Columns("E:G").ClearContents
errlog:
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
End With
End Sub
Sub FillCells()
On Error GoTo errlog
' Alles wat enige vertraging kan opleveren wordt hier uitgezet.
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
.DisplayAlerts = False
End With
Columns("B:G").ClearContents
'Tabel begint op kolom A, rij 5
Set Rng = Cells(5, 1).CurrentRegion
mx = WorksheetFunction.Max(Rng.Columns(1))
rw = Rng.Rows.Count
tmp = 0
nLoop = 100 'Na 100 keer geen resultaat wordt een 1 geplaatst
For Each c In Rng.Columns(1).Cells
If c = "Vrij" Or c < 1 Then GoTo nxt
CntLoop = 0
While CntLoop < nLoop
CntLoop = CntLoop + 1
tmp1 = Int((rw * Rnd(1)) + 1)
If Rng.Cells(tmp1, 1) = "Vrij" Then
GoTo col2
End If
If Rng.Cells(tmp1, 5) = "" Then
If Rng.Cells(tmp1, 1) = c.Offset(-1, 2) Or _
Rng.Cells(tmp1, 1) = c.Offset(0, 0) Then
GoTo col2
Else
c.Offset(0, 1) = Rng.Cells(tmp1, 1)
Rng.Cells(tmp1, 5) = "x"
GoTo nxtcol3
End If
Else
GoTo col2
End If
col2:
Wend
If CntLoop = nLoop Then
c.Offset(0, 1) = 1
End If
nxtcol3:
CntLoop = 0
While CntLoop < nLoop
CntLoop = CntLoop + 1
tmp1 = Int((rw * Rnd(1)) + 1)
If Rng.Cells(tmp1, 1) = "Vrij" Then
GoTo col3
End If
If Rng.Cells(tmp1, 6) = "" Then
If Rng.Cells(tmp1, 1) = c.Offset(-1, 2) Or _
Rng.Cells(tmp1, 1) = c.Offset(0, 1) Then
GoTo col3
Else
c.Offset(0, 2) = Rng.Cells(tmp1, 1)
Rng.Cells(tmp1, 6) = "x"
GoTo nxtcol4
End If
Else
GoTo col3
End If
col3:
Wend
If CntLoop = nLoop Then
c.Offset(0, 2) = Rng.Cells(tmp1, 1)
End If
nxtcol4:
CntLoop = 0
While CntLoop < nLoop
CntLoop = CntLoop + 1
tmp1 = Int((rw * Rnd(1)) + 1)
If Rng.Cells(tmp1, 1) = "Vrij" Then
GoTo col4
End If
If Rng.Cells(tmp1, 7) = "" Then
If Rng.Cells(tmp1, 1) = c.Offset(-1, 3) Or _
Rng.Cells(tmp1, 1) = c.Offset(0, 2) Then
GoTo col4
Else
c.Offset(0, 3) = Rng.Cells(tmp1, 1)
Rng.Cells(tmp1, 7) = "x"
GoTo nxt
End If
Else
GoTo col4
End If
col4:
Wend
If CntLoop = nLoop Then
c.Offset(0, 3) = 1
End If
nxt:
Next
'Sorteren van de tabel
With ActiveSheet.Sort
.SortFields.Clear
.SortFields.Add Key:=Rng.Cells(1, 1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Rng
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("E:G").ClearContents
errlog:
'Alles wordt weer aangezet.
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
End With
End Sub
Aat geen probleem heb het zelf al opgelost met je laatste code, was een quick fix en het werkt nu voortreffelijk bedankt voor al je hulp en geduld dat sommige andere niet hadden. Op naar de volgende vraag. :thumb:
Case closed.
We gebruiken essentiële cookies om deze site te laten werken, en optionele cookies om de ervaring te verbeteren.