Currently the macro is working on all cells.
If you want to restrict it to just specific cells, then we have a few ways that we have done that
For example
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$5" Or Target.Address = "$D$9" Or Target.Address = "$M$4" Or Target.Address = "$H$3" Then
If Target.Value = "" Then ' case a cell was emptied
Let Application.EnableEvents = False
Let Target.Value = "Enter Text Here"
Let Application.EnableEvents = True
With Target.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
End With
Else ' case a text was entered
With Target.Font
.ColorIndex = xlAutomatic
.TintAndShade = 0
End With
End If
Else
' Target is Not a cell to be acted on
End If
End Sub
Originally Posted by
Anshu
(Actually I want to use the code for more than 15 cells in a single sheet)
For a lot of cells, this other way we have done before may be a bit neater
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("B5,D9,M4,H3")) Is Nothing Then
If Target.Value = "" Then ' case a cell was emptied
Let Application.EnableEvents = False
Let Target.Value = "Enter Text Here"
Let Application.EnableEvents = True
With Target.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
End With
Else ' case a text was entered
With Target.Font
.ColorIndex = xlAutomatic
.TintAndShade = 0
End With
End If
Else
' Target is Not a cell to be acted on
End If
End Sub
Bookmarks