+ Reply to Thread
Results 1 to 4 of 4

Clear contents of cells on opening workbook

Hybrid View

jason1970 Clear contents of cells on... 06-13-2013, 07:51 AM
Mordred Re: Clear contents of cells... 06-13-2013, 08:47 AM
jason1970 Re: Clear contents of cells... 06-13-2013, 09:01 AM
Mordred Re: Clear contents of cells... 06-13-2013, 09:42 AM
  1. #1
    Registered User
    Join Date
    06-13-2013
    Location
    Ballymena
    MS-Off Ver
    Excel 2010
    Posts
    13

    Clear contents of cells on opening workbook

    Hi All

    I am wondering if it is possible to have a bit of VBA code to clear the contents of specific cells when opening a workbook?

    Any help greatly appreciated!

    Jason

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Clear contents of cells on opening workbook

    Yes it is possible. Which cells? The following example is should be placed in "ThisWorkbook" module:
    Private Sub Workbook_Open()
    
        Dim ws1 As Worksheet
        
        Set ws1 = Worksheets("Sheet1")
        
        ws1.Range("A5:G5").Cells.ClearContents
        
    End Sub
    You can pick any range of cells that you want.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    06-13-2013
    Location
    Ballymena
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Clear contents of cells on opening workbook

    Thanks for your reply Mordred, it worked perfectly! I wanted to select more than one range so I changed it to this:

    Private Sub Workbook_Open()
    Dim ws1 As Worksheet
    Set ws1 = Worksheets("Sheet1")
    ws1.Range("D4:D5,A9:L9").Cells.ClearContents
    End Sub

    Thanks again!

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Clear contents of cells on opening workbook

    No problem jason1970, don't forget to mark this as solved and if you're happy with my reply, click that star at the bottom left. I'd appreciate that!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1