title: VBA Random Mine Generation for Minesweeper
body: <p>I could not find any information on this problem in the Visual Basic language, but I am trying to generate 10 and only 10 random mines for a 5x5 Minesweeper game. My problem involves the number of mines. I often only generate 4 mines, or 10+ mines, and its always inconsistent. Here is my code: </p>
  
  <pre><code>Sub Minesweeper()
      Dim i As Single
      Dim Col As Single
      Dim Row As Single
      Dim BombArray(1 To 5, 1 To 5) As String
  
  
      'assignment of mines
      Do
          Row = Application.WorksheetFunction.RandBetween(1, 5)
          Col = Application.WorksheetFunction.RandBetween(1, 5)
      1
          If BombArray(Row, Col) &lt;&gt; "X" Then
              BombArray(Row, Col) = "X"
              Sheet1.Cells(4 + Row, 3 + Col).Value = BombArray(Row, Col)
  
          Else
              i = i + 1
              GoTo 1
          End If
      Loop Until i = 10
  
  End Sub
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>