VBA worksheet change event

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,516
Office Version
  1. 2016
Platform
  1. Windows
Hello Friends after a long time,

I need a small VBA code
When I enter "humayun" in cell A1 then A1 value should change to "humayun rayani" automatically

Regards,

Humayun
 
Pressing "Delete" does not stop the code working for me. It just puts " Humayan" in the cell.

Try running this version of the code, which will not add anything if you are deleting the contents of cell A1, and won't run if you delete rows, columns, or cells:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.CountLarge > 1 Then Exit Sub

If (Not Intersect(Target, Range("A1")) Is Nothing) And (Range("A1") <> "") Then

    Application.EnableEvents = False
    
    Range("A1").Value = Range("A1").Value & " Humyaun"
    
    Application.EnableEvents = True

End If

End Sub
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Pressing "Delete" does not stop the code working for me. It just puts " Humayan" in the cell.

Try running this version of the code, which will not add anything if you are deleting the contents of cell A1, and won't run if you delete rows, columns, or cells:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.CountLarge > 1 Then Exit Sub

If (Not Intersect(Target, Range("A1")) Is Nothing) And (Range("A1") <> "") Then

    Application.EnableEvents = False
   
    Range("A1").Value = Range("A1").Value & " Humyaun"
   
    Application.EnableEvents = True

End If

End Sub
there you go :)

Thanks Joe
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top