Consulting

Results 1 to 4 of 4

Thread: set cell value

  1. #1
    VBAX Regular
    Joined
    Oct 2009
    Posts
    14
    Location

    Smile set cell value

    Hi,

    Simple question, how do i set cell E2 = Week 5 everytime i create a new worksheet?

  2. #2
    VBAX Tutor
    Joined
    Nov 2006
    Location
    North East Pennsylvania, USA
    Posts
    203
    Location
    waka,

    You can use the Workbook_NewSheet Event to do what you have requested.


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


    1. Copy the below code, by highlighting the macro code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. And, paste the copied code into VBAProject, Microsoft Excel Objects, ThisWorkbook (on the right pane) by pressing the keys CTRL + V
    5. Press the keys ALT + Q to exit the Editor, and return to Excel



     
    Private Sub Workbook_NewSheet(ByVal Sh As Object)
      Range("E2") = "Week 5"
    End Sub

    Then, from any worksheet in your workbook, insert a new sheet.


    Have a great day,
    Stan

  3. #3
    VBAX Regular
    Joined
    Oct 2009
    Posts
    14
    Location
    Thanks for your response,

    Here is my code, I tried out this but isn't working. activesheet is "insert" worksheet.My E2 is always blank but i wanted to set it everytime i copy over it will automatic set E2 = "Week 5"

     
    Sheets("Template").Range("A2:E2").Copy
        ActiveSheet.Paste
        Application.CutCopyMode = False
        Range("E2") = "Week 5"

  4. #4
    VBAX Regular
    Joined
    Oct 2009
    Posts
    14
    Location
    I solved it by using this code

    Sheets("Template").Range("A2:E2").Copy
        ActiveSheet.Paste
        Application.CutCopyMode = False
        ActiveSheet.Range("E1") = "Week 5"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •