VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code will evaluate a Sudoku puzzle when go() is used as a macro in Excel. It won't directly

by Connor Broaddus (1 Submission)
Category: Games
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 15th December 2005
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code will evaluate a Sudoku puzzle when "go()" is used as a macro in Excel. It won't directly solve the puzzle, but it will list the

Rate This code will evaluate a Sudoku puzzle when go() is used as a macro in Excel. It won't directly



letters = "ABCDEFGHI"
For x = 1 To 9
    col = Mid$(letters, x, 1)
    For y = 1 To 9
        cell = col + CStr(y)
        cellval = Range(cell).Value
        If Not (cellval >= 1 And cellval <= 9) Then
            evaluate (cell)
        End If
    Next
Next
End Sub

Function evaluate(cell)
rown = Range(cell).Row
coln = Range(cell).Column
boxn = findbox(coln, rown)
'Range(cell).Font.Size = 12
Range(cell).Value = finish(combine(colcheck(coln), rowcheck(rown), boxcheck(boxn)))
End Function
Function rowcheck(rownum)
letters = "ABCDEFGHI"
presentr = "a111111111"
For i = 1 To 9
    cell = Mid$(letters, i, 1) + CStr(rownum)
    cellval = Range(cell).Value
    If cellval >= 1 And cellval <= 9 Then
        cellvalinv = 9 - cellval
        presentr = Left$(presentr, cellval) + "0" + Right$(presentr, cellvalinv)
    End If
Next
rowcheck = presentr
End Function
Function colcheck(colnum)
letters = "ABCDEFGHI"
presentc = "a111111111"
For i = 1 To 9
    cell = Mid$(letters, colnum, 1) + CStr(i)
    cellval = Range(cell).Value
    If cellval >= 1 And cellval <= 9 Then
        cellvalinv = 9 - cellval
        presentc = Left$(presentc, cellval) + "0" + Right$(presentc, cellvalinv)
    End If
Next
colcheck = presentc
End Function
Function boxcheck(boxnum)
boxnumx = Val(Mid$(boxnum, 1, 1))
boxnumy = Val(Mid$(boxnum, 2, 1))
letters = "ABCDEFGHI"
presentb = "a111111111"
coladd = 3 * boxnumx - 3
rowadd = 3 * boxnumy - 3
For y = 1 To 3
    rownum = y + rowadd
    For x = 1 To 3
        colnum = x + coladd
        cell = Mid$(letters, colnum, 1) + CStr(rownum)
        cellval = Range(cell).Value
        If cellval >= 1 And cellval <= 9 Then
            cellvalinv = 9 - cellval
            presentb = Left$(presentb, cellval) + "0" + Right$(presentb, cellvalinv)
        End If
    Next
Next
boxcheck = presentb
End Function
Function findbox(colnum, rownum)
If colnum >= 1 And colnum <= 3 Then
boxnumx = 1
End If
If colnum >= 4 And colnum <= 6 Then
boxnumx = 2
End If
If colnum >= 7 And colnum <= 9 Then
boxnumx = 3
End If
If rownum >= 1 And rownum <= 3 Then
boxnumy = 1
End If
If rownum >= 4 And rownum <= 6 Then
boxnumy = 2
End If
If rownum >= 7 And rownum <= 9 Then
boxnumy = 3
End If
findbox = CStr(boxnumx) + CStr(boxnumy)
End Function
Function combine(presentc, presentr, presentb)
present = "a111101111"
For i = 1 To 9
    x = i + 1
    pc = Val(Mid$(presentc, x, 1))
    pr = Val(Mid$(presentr, x, 1))
    pb = Val(Mid$(presentb, x, 1))
    pall = pc * pr * pb
    present = Left$(present, i) + CStr(pall) + Right$(present, 9 - i)
    combine = present
Next
End Function
Function finish(present)
presenta = ""
For i = 1 To 9
    pnum = Val(Mid$(present, i + 1, 1))
    If (pnum = 1) Then
    presenta = presenta + CStr(pnum * i)
    End If
Next
finish = presenta
End Function

Download this snippet    Add to My Saved Code

This code will evaluate a Sudoku puzzle when go() is used as a macro in Excel. It won't directly Comments

No comments have been posted about This code will evaluate a Sudoku puzzle when go() is used as a macro in Excel. It won't directly . Why not be the first to post a comment about This code will evaluate a Sudoku puzzle when go() is used as a macro in Excel. It won't directly .

Post your comment

Subject:
Message:
0/1000 characters