Excel Prank - Hide Text on Cell Selection

Add to Favorites
Author: | Edits: don

This prank will hide the contents of the currently selected cell and then show the contents once another cell is selected.

No data is changed or deleted using this prank, only the font color of the cell will be changed.

Before cell selection:

ff2a038e4c75177adc94df0153f9a78f.png

After cell selection (B2):

d681443ba9cacd83cd42820c6d0734bd.png

After next cell selection (C1):

ff5d2954b83d6f6442aba08dcc383a8f.png

Sections:

The Prank Macro Code

Where to Install

Notes

The Prank Macro Code

Public oldColor As Long
Public oldCell As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

'secondary cell selection - changes the font back to its original color
If Not oldCell = Empty Then

    'set the color of the original font
    Range(oldCell).Font.Color = oldColor

End If

'set the old cell
oldCell = Target.Address
'set the old color
oldColor = Target.Font.Color

'get the background color
newColor = Target.Interior.Color
'set the font to the background color
Target.Font.Color = newColor


End Sub

The top 2 lines of this code must go at the very top of the code window, above all macros.

6c8524fbe1520677a10097cea5ce445f.png

Note: this goes into a Worksheet code section and not a Module, look to the next section for instructions.

Where to Install

Worksheet code section.

Install this into the worksheet on which you want the prank to work.

Alt + F11 (VBA window) > look to the Project window on the left side of the window (Ctrl + R if you don't already see it) > double-click the name of the worksheet where you want this prank to work > put the code into the window that opens.

f2ee500bc76946964f732a551538e19c.jpg

Notes

This macro will only work on the worksheet or worksheets where you insert the code in the VBA window; you can't just apply it to the entire workbook at once.

Also, the macro works in the SelectionChange event; if you already have code in that event, then just copy/paste the above code without the lines that begin with Sub and End Sub.

The only way to stop this prank is to remove the code from the workbook or disable macros.

Download the attached file to see this macro in action.


Downloadable Files: Excel File

Question? Ask it in our Excel Forum


Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Tutorial Details
Downloadable Files: Excel File
Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course