title: Select and highlight one random cell using VBA
body: <p>I currently have an excel spreadsheet that when a user clicks Go, it assigns a new random number to the cells in the worksheet. The range value is between 1 and 500 in a 20 by 25 matrix. I want to randomly select and change the background color to red for only one cell every time a user clicks the 'Go' button. Code below is currently assigning random numbers to the cells and selecting and highlighting a random cell. However, when Go is clicked again the previously selected cell is still highlighted along with the newly selected cell. How can I code it to only highlight the newly selected cell when clicking Go?</p>
  
  <pre><code>Public Sub GenerateRandom()
      Set MyRange = Range("C4:AA23")
          For i = 1 To 500
              MyRange.Cells(i) = i
          Next
          For Each Cell In MyRange
              swapcell = 1 + Int(Rnd * 500)
              savedValue = Cell.Value
              Cell.Value = MyRange.Cells(swapcell).Value
              MyRange.Cells(swapcell) = savedValue
          Next
  
         With MyRange.Cells(1 + Int(Rnd * 500))
                  MyRange.Cells(RndBetween(1, 500)).Interior.Color = vbRed        
        End With        
      End Sub
  
      Public Function RndBetween(ByVal Low, ByVal High) As Integer
         Randomize
         RndBetween = Int((High - Low + 1) * Rnd + Low)
      End Function
  </code></pre>