VBA worksheet change event

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,501
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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
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,215,084
Messages
6,123,029
Members
449,092
Latest member
ikke

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