erik.van.geit
MrExcel MVP
- Joined
- Feb 1, 2003
- Messages
- 17,832
Hi,
don't know why I made this ... it just happened
could be nice to check out some functions and syntax
create new sheet or workbook
set cells to squares or run two extra lines: see code
paste code in sheet module (rightclick sheet - view code - paste)
learn and enjoy
Erik
don't know why I made this ... it just happened
could be nice to check out some functions and syntax
create new sheet or workbook
set cells to squares or run two extra lines: see code
paste code in sheet module (rightclick sheet - view code - paste)
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Erik Van Geit
'070221
'use arrows to catch the black square
'you could use the mouse
Dim c As Range
Dim ud As Integer 'up down
Dim rl As Integer 'right left
Dim pg As Range 'playground
'set cells to squares or run these two lines
'Cells.ColumnWidth = 1.71
'Cells.RowHeight = 12.75
'runnig next 3 lines each time could be avoided
Set pg = ActiveWindow.VisibleRange
Set pg = pg.Resize(pg.Rows.Count - 1, pg.Columns.Count - 1)
ActiveSheet.ScrollArea = pg.Address
Set c = pg.Find(1, lookat:=xlWhole)
If c Is Nothing Then
Set c = pg(1).Offset(Int(pg.Rows.Count * Rnd), Int(pg.Columns.Count * Rnd))
c = 1
End If
Do
ud = Choose(Int(Rnd * 5) + 1, -2, -1, 0, 1, 2)
rl = Choose(Int(Rnd * 5) + 1, -2, -1, 0, 1, 2)
If c.Row + ud <= 0 Then ud = 0
If c.Column + rl <= 0 Then rl = 0
Loop While Intersect(c.Offset(ud, rl), pg) Is Nothing
With c
.Interior.ColorIndex = xlNone
.Value = ""
With .Offset(ud, rl)
.Interior.ColorIndex = 1
.Value = 1
End With
End With
If ActiveCell = 1 Then
MsgBox "BRAVO", 64, "CATCH!!"
c = ""
c.Interior.ColorIndex = xlNone
End If
End Sub
Erik