adam234432
New Member
- Joined
- Jun 6, 2024
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
I got this code off another user on here. It allows me to create greyed out text from a template sheet. However, when you write in it the cell the text is removed and the new text becomes black. Then once deleted it goes back to the original grey text. I need to repeat this for multiple areas and I cant get it to work. e.g E8:E194. I am very new to using excel and this is my first time using VBA. So would appreciate any assistance. Thanks.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Colr As Long, Txt As String
If Target.Count = 1 Then
If Not Intersect(Target, Range("D8:D194")) Is Nothing Then
Txt = Sheets("CodeTemplate").Range(Target.Address).Value
End If
Application.EnableEvents = False
If Len(Target.Value) = 0 Or Target.Value = Txt Then
Target.Font.ColorIndex = 16
Target.Value = Txt
Else
Target.Font.ColorIndex = 1
End If
Application.EnableEvents = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Colr As Long, Txt As String
If Target.Count = 1 Then
If Not Intersect(Target, Range("D8:D194")) Is Nothing Then
Txt = Sheets("CodeTemplate").Range(Target.Address).Value
End If
Application.EnableEvents = False
If Len(Target.Value) = 0 Or Target.Value = Txt Then
Target.Font.ColorIndex = 16
Target.Value = Txt
Else
Target.Font.ColorIndex = 1
End If
Application.EnableEvents = True
End If
End Sub