Forum Discussion

janome's avatar
janome
Copper Contributor
Jan 26, 2024

How do I make my new Excel document and the worksheet within the document appear in the first cell

I need to display the text (e.g. "Hello") in the first cell of both my new document and the worksheet in it. Even if I delete the contents of the cell, save it, close the document, and open it again, the set cell (" Hello ") will still appear.

  • 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.

Resources