+ Reply to Thread
Results 1 to 5 of 5

Need macro to clear contents

  1. #1
    steve_sr2
    Guest

    Need macro to clear contents

    I need to create a macro to clear certain fields when sheet in workbook is
    opened.

    Thanks for the help!

  2. #2
    Tom Ogilvy
    Guest

    Re: Need macro to clear contents

    in the VBE, go to the project explorer and double click on the ThisWorkbook
    entry for your workbook/project

    In the resulting module, in the dropdowns at the top select Workbook form
    the left and Open from the right. This places

    Private Sub Workbook_Open()

    End Sub

    in the module. Put your code here

    Private Sub Workbook_Open()
    With ThisWorkbook.Worksheets("Sheet1")
    .Range("B9,F1,G3:H10,M11").ClearContents
    End With
    End Sub


    --
    Regards,
    Tom Ogilvy


    "steve_sr2" <[email protected]> wrote in message
    news:[email protected]...
    > I need to create a macro to clear certain fields when sheet in workbook is
    > opened.
    >
    > Thanks for the help!




  3. #3
    steve_sr2
    Guest

    Re: Need macro to clear contents

    Do I need to replace "ThisWorkbook.Worksheets("Sheet1")" with the names of my
    workbook & sheets?


    "Tom Ogilvy" wrote:

    > in the VBE, go to the project explorer and double click on the ThisWorkbook
    > entry for your workbook/project
    >
    > In the resulting module, in the dropdowns at the top select Workbook form
    > the left and Open from the right. This places
    >
    > Private Sub Workbook_Open()
    >
    > End Sub
    >
    > in the module. Put your code here
    >
    > Private Sub Workbook_Open()
    > With ThisWorkbook.Worksheets("Sheet1")
    > .Range("B9,F1,G3:H10,M11").ClearContents
    > End With
    > End Sub
    >
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "steve_sr2" <[email protected]> wrote in message
    > news:[email protected]...
    > > I need to create a macro to clear certain fields when sheet in workbook is
    > > opened.
    > >
    > > Thanks for the help!

    >
    >
    >


  4. #4
    Norman Jones
    Guest

    Re: Need macro to clear contents

    Hi Steve,

    > Do I need to replace "ThisWorkbook.Worksheets("Sheet1")"
    > with the names of my workbook & sheets?


    The ThisWorkbook property returns the workbook holding the code and,
    therefore, requires no change.

    Replace Sheet1 with the name of the sheet of interest.


    ---
    Regards,
    Norman



    "steve_sr2" <[email protected]> wrote in message
    news:[email protected]...
    > Do I need to replace "ThisWorkbook.Worksheets("Sheet1")" with the names of
    > my
    > workbook & sheets?
    >
    >
    > "Tom Ogilvy" wrote:
    >
    >> in the VBE, go to the project explorer and double click on the
    >> ThisWorkbook
    >> entry for your workbook/project
    >>
    >> In the resulting module, in the dropdowns at the top select Workbook form
    >> the left and Open from the right. This places
    >>
    >> Private Sub Workbook_Open()
    >>
    >> End Sub
    >>
    >> in the module. Put your code here
    >>
    >> Private Sub Workbook_Open()
    >> With ThisWorkbook.Worksheets("Sheet1")
    >> .Range("B9,F1,G3:H10,M11").ClearContents
    >> End With
    >> End Sub
    >>
    >>
    >> --
    >> Regards,
    >> Tom Ogilvy
    >>
    >>
    >> "steve_sr2" <[email protected]> wrote in message
    >> news:[email protected]...
    >> > I need to create a macro to clear certain fields when sheet in workbook
    >> > is
    >> > opened.
    >> >
    >> > Thanks for the help!

    >>
    >>
    >>




  5. #5
    Bob Phillips
    Guest

    Re: Need macro to clear contents

    Thisworkbook will refer to the workbook that contains the code. This will
    not need changing unless the code is in another workbook other than the one
    being manipulated, in which case you would use Activeworkbook.

    The sheet name should be changed to whatever your sheet is called.

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "steve_sr2" <[email protected]> wrote in message
    news:[email protected]...
    > Do I need to replace "ThisWorkbook.Worksheets("Sheet1")" with the names of

    my
    > workbook & sheets?
    >
    >
    > "Tom Ogilvy" wrote:
    >
    > > in the VBE, go to the project explorer and double click on the

    ThisWorkbook
    > > entry for your workbook/project
    > >
    > > In the resulting module, in the dropdowns at the top select Workbook

    form
    > > the left and Open from the right. This places
    > >
    > > Private Sub Workbook_Open()
    > >
    > > End Sub
    > >
    > > in the module. Put your code here
    > >
    > > Private Sub Workbook_Open()
    > > With ThisWorkbook.Worksheets("Sheet1")
    > > .Range("B9,F1,G3:H10,M11").ClearContents
    > > End With
    > > End Sub
    > >
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "steve_sr2" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > I need to create a macro to clear certain fields when sheet in

    workbook is
    > > > opened.
    > > >
    > > > Thanks for the help!

    > >
    > >
    > >




+ 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