Private Sub Worksheet_Change(ByVal Target As Range)
Const prefix As String = "xyz"
If Target.Column = 1 Then
Application.EnableEvents = False
Target.Value = prefix & Target.Value
Application.EnableEvents = True
End If
End Sub
Does the value in the cell have to physically change so that its value permanently has the prefix added to it or would simply formatting the cell so it just looked like the prefix was added be enough (with the actual value in the cell remaining exactly as entere)?I need an Excel VBA code to add a prefix in each cell of column A when ever i enter a text to Column A.
Private Sub Worksheet_Change(ByVal Target As Range)
Const prefix As String = "xyz"
If Target.Column = 1 Then
Application.EnableEvents = False
If Target.Value <> "" Then Target.Value = prefix & Target.Value
Application.EnableEvents = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Const prefix As String = "xyz"
If Target.Column = 1 Then
Application.EnableEvents = False
If Target.Value <> "" And Left(Target, Len(prefix)) <> prefix Then Target.Value = prefix & Target.Value
Application.EnableEvents = True
End If
End Sub