Excel Color Game

The_Game

New Member
Joined
Mar 27, 2015
Messages
31
For the excel Experts,

TEST YOUR KNOWLEDGE. I'm looking for a way to play with the buttons using colors (if at all possible). Here's an example of what I'm thinking:

Parameters: Game table is A1 to E10. (to keep things simple)
-Every cell is set to 1 of 6 random different colors; two of the same can exist next to another
-More than 6 colors can be used if its not to hard to program
-Add a reset button if at all possible

The Goal: by making every cell 1 of those 6 colors of your choosing.

How to Play: by selecting A1 (lets assume this cell is red) it turns adjecent cells (A2, B1) red. Cells diagonal to the selected cell change a different color, making it more difficult to complete.
-To make things easier (if needed), you can assign colors to each others if needed. By this I mean Red can be paired with Orange; Yellow with Green; Blue with Purple, etc...this way when I click A1, B2 will turn Orange. If I click B2, A1 will Turn Red. But this is just to make the game easier.

-If its possible to get complex with it, you can assign subsequent colors to others: Red to Orange; Orange to Yellow; Yellow to Green...etc.


If this doesn't seem possible, I at least got my idea out there. But what a brain teaser it would be to make a working product. If I'm missing any potential details, this idea is literally a rough draft.


Thanks guys!

The_Game
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi and welcome to the MrExcel Message Board.

I can give you a starter but if you want to develop it you will have to learn some VBA.

I think there is a slight problem with the gameplay. If you want to make everything the color of the top left cell then the game is easy. If you pick anything else then it is impossible.

I have written two macros. Both can be added in the VB editor as a Sheet macro. So go into the editor, double click a sheet name then paste in the code.
You will also need to add an ActiveX command button to the worksheet and this will need to be renamed to "Start" (without the quotes).

The line in the code where the game range is set is commented and you can change the range.
The row where the colors are set is also commented. Just add numbers in the same format.

The macro attached to the button will put a random number in each cell. It then associates each number to a color. The font and the background color are then changed to be the same color as defined by the random number. So you can't see the numbers. To do this, the macro uses Excel's Conditional Formatting.

When you change the selection the other macro is called. This checks that the selected cell and the changed ones will all be in the conditionally formatted area. If they are then the colors are changed.

Enjoy:
Code:
rivate Sub Start_Click()

    Dim NColors As Integer
    Dim c As Range
    Dim r As Range
    Dim arrCol As Variant
    
    Set r = ActiveSheet.Range("A1:E10")                                     ' Change game range here
    arrColors = Array(255, 49407, 65535, 5296274, 15773696, 6299648)        ' Add colors here
    
    ' Count the number of colors
    NColors = UBound(arrColors) + 1
    
    ' Clear all cells in the sheet
    ActiveSheet.Cells.Clear
    
    ' Set each cell in the game to a random color up to the number of colors
    For Each c In r
        c.Value = Int(NColors * Rnd)
    Next

    ' Clear any existing Conditional Formatting
    ActiveSheet.Cells.FormatConditions.Delete
    
    ' Use the random number in the game cells to set the font and fill colors
    For i = 1 To NColors
        With r
            .FormatConditions.Add Type:=xlExpression, Formula1:="=" & r.Cells(1, 1).Address(False, False) & "=" & i - 1
            With .FormatConditions(i)
                .Font.Color = arrColors(i - 1)
                .Interior.Color = arrColors(i - 1)
            End With
        End With
    Next
   
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Target
        ' Ensure only one cell is selected
        If .Count = 1 Then
            ' Check to see if cell has Conditional Formatting - If so then assume it is a game cell
            If .Offset(0, 0).FormatConditions.Count > 1 Then
                ' Check if the cell on the next row is a game cell, if so change it
                If .Offset(1, 0).FormatConditions.Count > 1 Then .Offset(1, 0).Value = .Value
                ' Check if the cell in the next column is a game cell, if so change it
                If .Offset(0, 1).FormatConditions.Count > 1 Then .Offset(0, 1).Value = .Value
            End If
        End If
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,553
Members
452,928
Latest member
101blockchains

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top