Forum Discussion
AshaKantaSharma
Aug 20, 2024Iron Contributor
For Existing Workbook
Create a Workbook with "Hello" in A1:
Open an existing workbook or create a new one.
Enter "Hello" in cell A1.
Save the workbook.
Add a Worksheet Event to Keep "Hello" in A1:
Open the workbook.
Press ALT + F11 to open the VBA editor.
Insert a new module (Insert > Module) and paste the following code:
vba
Copy code
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Not Intersect(Target, Sh.Range("A1")) Is Nothing Then
If Target.Value <> "Hello" Then
Application.EnableEvents = False
Target.Value = "Hello"
Application.EnableEvents = True
End If
End If
End Sub
Save and close the VBA editor.
This code will ensure that cell A1 always displays "Hello" even if someone tries to change it. Note that this will apply to any worksheet in the workbook.
Create a Workbook with "Hello" in A1:
Open an existing workbook or create a new one.
Enter "Hello" in cell A1.
Save the workbook.
Add a Worksheet Event to Keep "Hello" in A1:
Open the workbook.
Press ALT + F11 to open the VBA editor.
Insert a new module (Insert > Module) and paste the following code:
vba
Copy code
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Not Intersect(Target, Sh.Range("A1")) Is Nothing Then
If Target.Value <> "Hello" Then
Application.EnableEvents = False
Target.Value = "Hello"
Application.EnableEvents = True
End If
End If
End Sub
Save and close the VBA editor.
This code will ensure that cell A1 always displays "Hello" even if someone tries to change it. Note that this will apply to any worksheet in the workbook.