Announcement

Collapse
No announcement yet.

Put Grayed Text Into Input Cells for Instructions which Reappears if Input is Deleted

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Put Grayed Text Into Input Cells for Instructions which Reappears if Input is Deleted



    I would like to have grayed-out text in some cells to give users short instructions for that particular cell. If they type something in that cell, the text they input is in plain dark black...but if they delete what they type, the cell goes back to having the grayed-out text.

    So just for an example, a cell might say ENTER LAST NAME. When the user starts typing in that cell, ENTER LAST NAME disappears and their text shows up in DARK BLACK. BUT if they delete what they typed, ENTER LAST NAME reappears.

    I suppose what I want is conditional formatting which allows me to add text if the cell is empty...but if conditional formatting allows you to 'format' with specific text, I can't find it.

    Does anyone have a suggestion?

    Thank you.

  • #2
    Re: Put Grayed Text Into Input Cells for Instructions which Reappears if Input is Del

    Insert this into sheet code
    Code:
    Sub RangeSetEmpty()
        Replace_Blanks [A1:A10], "Enter Last Name"
    End Sub
    Apply the conditonal formats, you can go a step further and adding the above into a worksheet event change to do what you require.

    Comment


    • #3


      Re: Put Grayed Text Into Input Cells for Instructions which Reappears if Input is Del

      Adjust range reference to suit.
      Code must go into the worksheet module. Right-click the sheet tab > View Code > Paste in the code > adjust code > close VB Editor

      Code:
      Option Explicit
      
      Private Sub Worksheet_Change(ByVal Target As Range)
      
          If Target.Cells.Count > 1 Then Exit Sub
          
          If Not Intersect(Target, Range("A1:A10")) Is Nothing Then
              Select Case Target.Value
                  Case Is = ""
                      Target.Value = "Enter Last Name"
                      Target.Font.ColorIndex = 15
                  Case Else
                      Target.Font.ColorIndex = 1
              End Select
          End If
          
      End Sub
      AAE
      ----------------------------------------------------

      Forum Rules | Message to Cross Posters | How to use Tags

      Comment

      Working...
      X