+ Reply to Thread
Results 1 to 16 of 16

Clear cell range on multiple sheets if cell on one sheet is modified.

  1. #1
    Registered User
    Join Date
    07-05-2012
    Location
    Delaware
    MS-Off Ver
    Excel 2010
    Posts
    11

    Clear cell range on multiple sheets if cell on one sheet is modified.

    The script below works perfect, except I need it to clear contents on worksheets labeled "Monday, Tuesday, Wednesday, Thursday, Friday" when cell (U2) on "Monday" is changed. HELP!!!


    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("u2")) Is Nothing Then Exit Sub
    [H8:O27,H30:O41,U30:U41].ClearContents
    End Sub

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    Welcome to the board!

    Please Login or Register  to view this content.
    Last edited by Tinbendr; 07-05-2012 at 01:58 PM.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    07-05-2012
    Location
    Delaware
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    David,

    Thanks for your response, however I am now getting a compile error:
    "Block If without End If"

    I know this is basic debugging but I am super new to VBA and need this spoon fed to me. Sorry and Thanks.

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    Oops! Copy/Paste error.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-05-2012
    Location
    Delaware
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    Now I'm getting a "Run-time error '450': Wrong number of arguments or invalid property assignment" I have attached a copy of the workbook. Please see attached.

    Thanks.
    blank template (1 day) v4.2.xls

  6. #6
    Registered User
    Join Date
    07-05-2012
    Location
    Delaware
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    oops wrong file. I forgot to save changes. try this one
    blank template (1 day) v4.2.xls

  7. #7
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    It doesn't like the quotes mid-stream on the Range argument:

    Please Login or Register  to view this content.

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    Try this
    Please Login or Register  to view this content.
    Last edited by royUK; 07-05-2012 at 02:38 PM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  9. #9
    Registered User
    Join Date
    07-05-2012
    Location
    Delaware
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    Is there a way to ungroup them when it is done clearing the contents, because if I input any data into any sheet in the group it copies the data to the other sheets.

  10. #10
    Registered User
    Join Date
    07-05-2012
    Location
    Delaware
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    Quote Originally Posted by wallyeye View Post
    It doesn't like the quotes mid-stream on the Range argument:

    Please Login or Register  to view this content.


    Thanks a million It works like a charm.

  11. #11
    Registered User
    Join Date
    07-05-2012
    Location
    Delaware
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    Thank you everyone!!!

  12. #12
    Registered User
    Join Date
    07-05-2012
    Location
    Delaware
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    Follow up,

    I submitted this unprotected, but when I password protected the sheet it will no longer work. I'm getting "Run-time error '1004': The cell or chart that you are trying to change is protected and therefore read-only. To modify a protected cell or chart, first remove protection using the Unprotect Sheet command (Review tab, Changes group). You may be prompted for a password." Can you please amend the code below to compensate for this?

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("u2")) Is Nothing Then
    Dim WSNames As Variant
    Dim A As Long

    Application.EnableEvents = False
    WSNames = Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Vacation", "Holiday", "Funeral", "Jury")
    For A = LBound(WSNames) To UBound(WSNames)
    Worksheets(WSNames(A)).Range("H8:O27,H30:O41,U30:U41").ClearContents
    Next
    Application.EnableEvents = False
    End If

    End Sub

  13. #13
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    I have a sheet protection function I use, it allows me to store the protection password in one location, rather than everywhere I need to protect/unprotect the sheet:

    Please Login or Register  to view this content.
    Put it in a new module, change the password to match yours, then change the routine:

    Please Login or Register  to view this content.
    You can add parameters to the .Protect statement, check the help files. I had some spreadsheets I support that had 40-50 locations that protected/unprotected the worksheets, this function cut down on maintenance quite a bit. You can also pass worksheets identified with their codenames to it.

  14. #14
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    I added the ungroup line, it should be


    Please Login or Register  to view this content.
    To get round the the protection issue you can use Protect with UserInterface, that allows macros to work on protected sheets.
    Last edited by royUK; 07-06-2012 at 02:10 AM.

  15. #15
    Registered User
    Join Date
    07-05-2012
    Location
    Delaware
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    Hello everyone,

    I'm back with a follow up modification request.

    I would like to replace the worksheet names "Monday, etc" and set this script to clear the cells throughout the entire workbook. Can anyone help me?

    Thanks a million in advance.

  16. #16
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: Clear cell range on multiple sheets if cell on one sheet is modified.

    I don't know how to select all the worksheets in a dynamic array like the previous example, this loops through each worksheet:

    Please Login or Register  to view this content.

+ 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