ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How do I format cells to reveal or hide contents when clicked? (https://www.excelbanter.com/excel-discussion-misc-queries/215355-how-do-i-format-cells-reveal-hide-contents-when-clicked.html)

Nanne

How do I format cells to reveal or hide contents when clicked?
 
Please help, I am trying to create a game for maths lessons. How do I set a
cell so that it's contents appear when I click once, then disappear on the
next click?

Gary''s Student

How do I format cells to reveal or hide contents when clicked?
 
How about double-click??

Put the following event macro in the worksheet code area:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Cancel = True
With Target.Font
If .ColorIndex = xlAutomatic Then
.ColorIndex = 2
Else
.ColorIndex = xlAutomatic
End If
End With
End Sub

This assumes that the backgound color of a cell is white. The first
double-click on a cell changes the font to white, the second double-click on
that cell changes the font color to black.


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu200823


"Nanne" wrote:

Please help, I am trying to create a game for maths lessons. How do I set a
cell so that it's contents appear when I click once, then disappear on the
next click?


Gord Dibben

How do I format cells to reveal or hide contents when clicked?
 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const myRange As String = "A1:A10"
On Error GoTo endit
Application.EnableEvents = False
Me.Unprotect Password:="justme"
If Not Intersect(Target, Me.Range(myRange)) Is Nothing Then
With Me.Range(myRange).Cells
.FormulaHidden = True
.Locked = False
End With
With Target
If .NumberFormat = ";;;" Then
.NumberFormat = General
Else
.NumberFormat = ";;;"
End If
End With
End If
endit:
Me.Protect Password:="justme"
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP


On Mon, 5 Jan 2009 08:59:00 -0800, Nanne
wrote:

Please help, I am trying to create a game for maths lessons. How do I set a
cell so that it's contents appear when I click once, then disappear on the
next click?




All times are GMT +1. The time now is 08:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com