Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Target.Address = Range("A1").Address Then
If Target.Value = "humayun" Then
Application.EnableEvents = False
Target.Value = "humayun rayani"
Application.EnableEvents = True
End If
End If
End Sub
Simple change:My Bad, for not putting up my question correctly
change A1 value to A1 value and "rayani"
if I enter Abdul it should be changed to "abdul rayani" as soon as i press enter
if i enter Humayun it should be chnaged to "humayun rayani" as soon as i press enter
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Target.Address = Range("A1").Address Then
Application.EnableEvents = False
Target.Value = Target.Value & " rayani"
Application.EnableEvents = True
End If
End Sub
Thanks JoeSimple change:
VBA Code:Private Sub Worksheet_Change(ByVal Target As Range) If Target.CountLarge > 1 Then Exit Sub If Target.Address = Range("A1").Address Then Application.EnableEvents = False Target.Value = Target.Value & " rayani" Application.EnableEvents = True End If End Sub
hello, one more thingYou are welcome.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Application.EnableEvents = False
Range("A1").Value = Range("A1").Value & " Humyaun"
Application.EnableEvents = True
End If
End Sub
Nothing wrong with that code, it should work as long as:hello, one more thing
what is wrong when i write the code like below
why it is not working
VBA Code:Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Range("A1")) Is Nothing Then Application.EnableEvents = False Range("A1").Value = Range("A1").Value & " Humyaun" Application.EnableEvents = True End If End Sub
Sub ReEnableEvents()
Application.EnableEvents = True
End Sub
ok but when i press delete then the code stops working next timeNothing wrong with that code, it should work as long as:
- You have placed it in the proper sheet module
- Events are enabled
When you have code that enables/disables events, sometimes if you are testing you may accidentally disable it and not re-enable it. In that case, all events will stop working.
You can re-enable them by manually running this code:
VBA Code:Sub ReEnableEvents() Application.EnableEvents = True End Sub