Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default 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?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default 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?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell contents not recognised untill clicked Ade Excel Discussion (Misc queries) 3 March 28th 07 02:08 AM
auto highlighting of cells when clicked on beyondthevail Excel Discussion (Misc queries) 1 March 1st 07 02:50 AM
set up a macro in Excel to color cells when clicked Rebecca Shearer Excel Worksheet Functions 3 September 19th 05 11:31 AM
Can I format a cell to fill red when clicked with mouse (Excel)? mike.wilson Excel Worksheet Functions 4 May 2nd 05 08:01 AM
Ho do I reveal the hidden format codes? box Excel Worksheet Functions 1 March 23rd 05 12:08 AM


All times are GMT +1. The time now is 03:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"