Show cell contents on click

_saiko

New Member
Joined
Jul 2, 2011
Messages
6
Using a basic white color method to hide cell values I can successfully use this code to show (change color to black) the text inside a cell:

HTML:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Font.ColorIndex = 2 Then
    Target.Font.ColorIndex = 1
End If
End Sub
Now i wonder how to "restore" white color back for the cell contents after deselect?


Also is it possible to change the text color to white (or to replace the text with something else) immediately after the input?
 
Last edited:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
How about this

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Static lastRange As Range
    
    If lastRange Is Nothing Then
        UsedRange.Font.ColorIndex = 2
    Else
        lastRange.Font.ColorIndex = 2
    End If
    Set lastRange = Target
    
    Target.Font.ColorIndex = xlAutomatic
End Sub
 
Upvote 0
This will restrict its action to a specified range.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Const CLWht As Long = 2
    Static lastRange As Range
    Dim actionRange As Range
    Set actionRange = Range("A1:D5"): Rem adjust
    
    If lastRange Is Nothing Then
        actionRange.Font.ColorIndex = CLWht
    Else
        On Error Resume Next
        Application.Intersect(actionRange, lastRange).Font.ColorIndex = CLWht
        On Error GoTo 0
    End If
    
    Set lastRange = Target
    
    On Error Resume Next
    Application.Intersect(actionRange, Target).Font.ColorIndex = xlAutomatic
    On Error GoTo 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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