joopmetstroop
Gebruiker
- Lid geworden
- 13 jan 2023
- Berichten
- 8
ik probeer een script te maken die een sudoku oplost en invult.
dit is mijn code, kan iemand mij verder helpen?
dit is deel 1 die werkt
dit deel werkt nog niet:
dit is mijn code, kan iemand mij verder helpen?
PHP:
Sub GetCandidates()
For num = 1 To 9
If WorksheetFunction.CountIf(sud.Range("B2:J10"), num) < 9 Then
For Each cell In sud.Range("B2:J10").SpecialCells(xlCellTypeBlanks)
If WorksheetFunction.CountIf(sud.Rows(cell.Row), num) = 0 And _
WorksheetFunction.CountIf(sud.Columns(cell.Column), num) = 0 And _
WorksheetFunction.CountIf(sud.Range(qrng(cell.Row, cell.Column)), num) = 0 Then _
sol.Cells(cell.Row, cell.Column) = sol.Cells(cell.Row, cell.Column) & num
Next cell
End If
Next num
End Sub
Private Function qrng(r As Integer, c As Integer) As String
If c < 5 Then
If r < 5 Then
qrng = "B24"
ElseIf r < 8 Then
qrng = "B57"
Else
qrng = "B810"
End If
ElseIf c < 8 Then
If r < 5 Then
qrng = "E2:G4"
ElseIf r < 8 Then
qrng = "E5:G7"
Else
qrng = "E8:G10"
End If
Else
If r < 5 Then
qrng = "H2:J4"
ElseIf r < 8 Then
qrng = "H5:J7"
Else
qrng = "H8:J10"
End If
End If
End Function
dit is deel 1 die werkt
dit deel werkt nog niet:
PHP:
Sub solvesingles()
Dim cel As Range, numadded As Boolean
For Each cell In sol.Range("B2:J10").SpecialCells(xlTextValues)
If Len(cell.Value) = 1 Then
sud.Cells(cell.Row, cell.Column) = sol.Cells(cell.Row, cell.Column).Value
numadded = True
End If
Next cell
If WorksheetFunction.CountA(sud.Range("B2:J10")) < 81 Then
If numadded = True Then
Call GetCandidates
Else
Call findhiddensingles
End If
End If
End Sub
Sub findhiddensingles()
'rows
For r = 2 To 10
For c = 2 To 10
hints = sol.Cells(r, c).Value
If hints <> "" Then
For i = 1 To Len(hints)
num(i) = Mid(hints, i, 1)
For c2 = 2 To 10
hints2 = sol.Cells(r, c2).Value
If hints2 <> "" And c2 <> c And _
InStr(hints2, num(i)) > 0 Then notsingle = True
Next c2
If notsingle = False Then sud.Cells(r, c) = num(i)
Next i
End If
Next c
Next r
'colums next
End Sub
Laatst bewerkt: