Results 1 to 4 of 4
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,469
    Thanks
    30
    Thanked 62 Times in 58 Posts

    Want to clear cells on open

    I put the following in ThisWorkbook:


    Sub auto_open()

    Worksheets("Sheet1").Range("D16:F16").ClearContent s

    End Sub

    Saved the workbook as xlsm; reopened it; but, the three cells were not cleared.

    What am I doing wrong? (Excel 2010)

    It's WORKBOOK not Auto...hmmm.
    Last edited by kweaver; 2011-08-19 at 22:05. Reason: found it.

  2. #2
    2 Star Lounger
    Join Date
    Jun 2011
    Posts
    188
    Thanks
    62
    Thanked 0 Times in 0 Posts
    Hi kweaver,

    You have to follow 2 steps...

    * Paste the below code in e.g test(worksheet)

    1.
    Option Explicit
    Private Sub Workbook_Open()
    Call Auto_Open
    End Sub

    * Paste the below 2 codes in the module Alt+F11
    2.

    Sub Auto_Open()
    myRoutine
    End Sub

    Sub myRoutine()
    Worksheets("test").Range("D16:F16").ClearContents
    End Sub

    Note that your worksheet name change according to your need that sample file is attached with...

    Thanks
    farrukh
    Attached Files Attached Files

  3. #3
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    Goto VBA (Alt-F11) and copy this code into the "ThisWorkbook" Module:

    Code:
    Private Sub Workbook_Open()
      Worksheets("Sheet1").Range("D16:F16").ClearContents
    End Sub
    Steve

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    You can use Auto_open but the code has to be in a normal module, not the ThisWorkbook one.
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

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