Terry wants to make a different sized maze and I think that is a great idea. Perhaps you remember that I built a maze in excel last week, if you don´t check it out.

This workbook allows you to choose the number of rows and columns you want, as long as it is between 1 and 255. You can also specify the column width and row height.

The following maze has 30 columns and 30 rows.

Customize maze3

This maze has 200 columns and 200 rows and the column width is 3 px and row height is 3 px.

200x200 excel maze

This maze has 60 columns and 40 rows.

60x40 excel maze

VBA Code

Sub BuildMaze()
Dim loc() As Variant
Dim path(0 To 3)
Dim visloc() As Variant
ReDim visloc(1, 0)
Application.ScreenUpdating = False
Worksheets("Maze3").Select
ActiveWindow.DisplayHeadings = False
ActiveWindow.DisplayGridlines = False
Cells.Select
Range(Cells(1, 1), Cells(260, 260)) = ""
With Worksheets("Customize maze")
    ReDim loc(0 To .Range("C7").Value, 0 To .Range("C4").Value)
    Selection.ColumnWidth = (.Range("C5").Value / 11.9047619)
    Selection.RowHeight = (.Range("C8").Value / (4 / 3))
    Range(Cells(2, 2), Cells((.Range("C7").Value + 1), (.Range("C4").Value) + 1)) = 1
    StartR = Int(Rnd * (.Range("C7").Value - 2)) + 1
    StartC = Int(Rnd * (.Range("C4").Value - 2)) + 1
End With
Range("A1").Select
Application.ScreenUpdating = True
Application.ScreenUpdating = False
Range("B2").Cells(StartR, StartC) = "S"
loc(StartR, StartC) = 1
visloc(0, 0) = StartR
visloc(1, 0) = StartC
Ubr = Worksheets("Customize maze").Range("C7").Value
Ubc = Worksheets("Customize maze").Range("C4").Value
Do
c = 0
For i = 0 To 3
    path(i) = 0
Next i
If visloc(0, UBound(visloc, 2)) - 2 >= 1 Then
    If loc(visloc(0, UBound(visloc, 2)) - 1, visloc(1, UBound(visloc, 2))) <> 1 And _
    loc(visloc(0, UBound(visloc, 2)) - 2, visloc(1, UBound(visloc, 2))) <> 1 And _
    loc(visloc(0, UBound(visloc, 2)) - 1, visloc(1, UBound(visloc, 2)) + 1) <> 1 And _
    loc(visloc(0, UBound(visloc, 2)) - 1, visloc(1, UBound(visloc, 2)) - 1) <> 1 Then
        path(0) = 1
        c = 1
    End If
End If
If visloc(0, UBound(visloc, 2)) + 2 <= Ubr Then
    If loc(visloc(0, UBound(visloc, 2)) + 1, visloc(1, UBound(visloc, 2))) <> 1 And _
    loc(visloc(0, UBound(visloc, 2)) + 2, visloc(1, UBound(visloc, 2))) <> 1 And _
    loc(visloc(0, UBound(visloc, 2)) + 1, visloc(1, UBound(visloc, 2)) + 1) <> 1 And _
    loc(visloc(0, UBound(visloc, 2)) + 1, visloc(1, UBound(visloc, 2)) - 1) <> 1 Then
        c = 1
        path(1) = 1
    End If
End If
If visloc(1, UBound(visloc, 2)) - 2 >= 1 Then
    If loc(visloc(0, UBound(visloc, 2)), visloc(1, UBound(visloc, 2)) - 1) <> 1 And _
    loc(visloc(0, UBound(visloc, 2)), visloc(1, UBound(visloc, 2)) - 2) <> 1 And _
    loc(visloc(0, UBound(visloc, 2)) + 1, visloc(1, UBound(visloc, 2)) - 1) <> 1 And _
    loc(visloc(0, UBound(visloc, 2)) - 1, visloc(1, UBound(visloc, 2)) - 1) <> 1 Then
        c = 1
        path(2) = 1
    End If
End If
If visloc(1, UBound(visloc, 2)) + 2 <= Ubc Then
    If loc(visloc(0, UBound(visloc, 2)), visloc(1, UBound(visloc, 2)) + 1) <> 1 And _
    loc(visloc(0, UBound(visloc, 2)), visloc(1, UBound(visloc, 2)) + 2) <> 1 And _
    loc(visloc(0, UBound(visloc, 2)) + 1, visloc(1, UBound(visloc, 2)) + 1) <> 1 And _
    loc(visloc(0, UBound(visloc, 2)) - 1, visloc(1, UBound(visloc, 2)) + 1) <> 1 Then
        c = 1
        path(3) = 1
    End If
End If
If c = 0 Then
        If Ccount > Tcount Then
            Tcount = Ccount
            Er = visloc(0, UBound(visloc, 2))
            Ec = visloc(1, UBound(visloc, 2))
        End If
        Ccount = Ccount - 1
    ReDim Preserve visloc(UBound(visloc, 1), UBound(visloc, 2) - 1)
Else
    c = 0
    Do Until c <> 0
        rrand = Int(Rnd * 4)
        If path(rrand) = 1 Then c = rrand + 1
    Loop
    ReDim Preserve visloc(UBound(visloc, 1), UBound(visloc, 2) + 1)
    Select Case c
        Case 1
            visloc(0, UBound(visloc, 2)) = visloc(0, UBound(visloc, 2) - 1) - 1
            visloc(1, UBound(visloc, 2)) = visloc(1, UBound(visloc, 2) - 1)
        Case 2
            visloc(0, UBound(visloc, 2)) = visloc(0, UBound(visloc, 2) - 1) + 1
            visloc(1, UBound(visloc, 2)) = visloc(1, UBound(visloc, 2) - 1)
        Case 3
            visloc(0, UBound(visloc, 2)) = visloc(0, UBound(visloc, 2) - 1)
            visloc(1, UBound(visloc, 2)) = visloc(1, UBound(visloc, 2) - 1) - 1
        Case 4
            visloc(0, UBound(visloc, 2)) = visloc(0, UBound(visloc, 2) - 1)
            visloc(1, UBound(visloc, 2)) = visloc(1, UBound(visloc, 2) - 1) + 1
    End Select
    Ccount = Ccount + 1
    Range("B2").Cells(visloc(0, UBound(visloc, 2)), visloc(1, UBound(visloc, 2))) = ""
    loc(visloc(0, UBound(visloc, 2)), visloc(1, UBound(visloc, 2))) = 1
    DoEvents
End If
k = k + 1
If (k / 200) - Int(k / 200) = 0 Then
    Application.ScreenUpdating = True
    Application.ScreenUpdating = False
End If
Loop Until visloc(0, UBound(visloc, 2)) = StartR And visloc(1, UBound(visloc, 2)) = StartC
Application.ScreenUpdating = True
Range("B2").Cells(Er, Ec) = "B"
End Sub

Download excel *.xlsm file

Customize maze.xlsm