Event generated with a mouse-click

hockey123

New Member
Joined
Nov 10, 2010
Messages
12
Hello,
I am trying to design something with the same concept as a bingo let's say..
The player has 42 choices (1 to 42), which are in Range("B5:C25")
He has to pick 6 numbers (one at a time) out of the 42 numbers.
When a number is chosen (with a mouse-click on the number), I want it to appear in the Range("E5:E10") in chronological order (i.e if the player picks 40,30,8,3,20 ; these number should appear as 3,8,20,30,40 in the Range("B5:C25"). The cells of the 6 chosen numbers should also appear in red after being picked.

Any help would be greatly appreciated !!
<!-- / message --><!-- BEGIN TEMPLATE: ad_showthread_firstpost_sig --><!-- END TEMPLATE: ad_showthread_firstpost_sig -->
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Each Sheet has already set up and ready to use a Cell Double-Click Event;
If using that instead of a Single-Click, you are in business; The event automatically returns the target cell which is what you need,,,
 
Upvote 0
With the sheet that has the values in B5:C25, right-click on the sheet tab and select View Code from the pop-up menu. Paste the code below in the VBA edit window.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim counter As Byte
    
    If Target.Count = 1 Then
    
        If Not Intersect(Target, Range("B5:C25")) Is Nothing Then
        
            counter = Application.Count(Range("E5:E10"))
            
            If Target.Font.ColorIndex <> 3 Then
            
                If counter < 6 Then
                
                    Range("E5").Offset(counter).Value = Target.Value
                    Target.Font.ColorIndex = 3
                    
                    Range("E5:E10").Sort Key1:=Range("E5"), Order1:=xlAscending, Header:=xlNo, _
                                    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
                                    DataOption1:=xlSortNormal
                End If
                
            Else
                Target.Font.ColorIndex = xlAutomatic
                
                On Error Resume Next
                    Range("E5:E10").Find(Target.Value, Lookat:=xlWhole).ClearContents
                On Error GoTo 0
                
                Range("E5:E10").Sort Key1:=Range("E5"), Order1:=xlAscending, Header:=xlNo, _
                                OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
                                DataOption1:=xlSortNormal
                
            End If
        End If
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,835
Messages
6,127,167
Members
449,368
Latest member
JayHo

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