In this game, students fence off an area of the drill field and divide it up into
Question:
In this game, students fence off an area of the drill field and divide it up into a series of equally sized squares. (We will assume there are 500 such squares organized into a 20 by 25 matrix.) Each square is randomly assigned a unique integer value between 1 and 500 (i.e., each number between 1 and 500 is used exactly once).
The following Excel spreadsheet needs to automate the task of assigning random numbers to the squares, and selecting the winning square. Whenever the user clicks the "Go" button, the VBA program should assign new random numbers to the cells in the worksheet and also randomly select the winning cell and change its background color to red (or some other color).
Requirements & Hints:
- Can use formulas in the worksheet to create the row and column headings in the table. However, there should not be any other formulas in the worksheet. All the random numbers should be generated in VBA and placed in the cells as numeric constants (not cell formulas).
- In VBA, numbers between 1 and 500 can be randomly generated via: 1 + Int(Rnd * 500))
- Need to figure out how to make VBA loop through the 500 cells in the range containing the numbers.
- There are a variety of ways to approach this problem. One way is to first fill the range sequentially with the integers from 1 to 500. Then, generate a random cell number between 1 and 500 and then swap the value in the current cell with the value that is in whatever cell number you generate randomly.
Putting the "Go" button in your application
Once the VBA code is working, add a "Go" button to the spreadsheet that the user can click to execute.
Introduction to Operations and Supply Chain Management
ISBN: 978-0132747325
3rd edition
Authors: Cecil B. Bozarth, Robert B. Handfield