+ Reply to Thread
Results 1 to 4 of 4

ClearContents of a range of cells in on sheets bar 5

  1. #1
    Registered User
    Join Date
    03-07-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003
    Posts
    3

    Question ClearContents of a range of cells in on sheets bar 5

    This works:
    Hi, I have made a bit of code to ClearContents of a range of cells. At the moment in clears every sheet expect one of my choosing. But I need to choose 5 sheets instead of one.

    Can any one help.

    Thanks.

    Option Explicit

    Sub ClearA1toJ92()

    Dim ws As Worksheet
    Dim TheName As String

    TheName = "Sheet2"
    For Each ws In ActiveWorkbook.Worksheets
    If Not ws.Name = TheName Then
    ws.Range("A1:J9").ClearContents
    End If
    Next ws

    End Sub

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

    Re: ClearContents of a range of cells in on sheets bar 5

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    03-07-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: ClearContents of a range of cells in on sheets bar 5

    I now have this (See Below), which works. But I now need to do the same but instead of ClearContents I need to unlock cells.

    The vba code when recording a new macro is:
    Selection.Locked = False
    Selection.FormulaHidden = False


    Thanks

    Jason


    Option Explicit

    Sub exam()
    Dim wks As Worksheet

    For Each wks In ThisWorkbook.Worksheets
    Select Case wks.Name
    Case "Sheet3", "Sheet4", "Sheet5", "Sheet6", "Sheet7"
    Case Else
    wks.Range("A1:J9").ClearContents
    End Select
    Next
    End Sub

  4. #4
    Registered User
    Join Date
    03-07-2011
    Location
    Essex, England
    MS-Off Ver
    Excel 2003
    Posts
    3

    Smile Re: ClearContents of a range of cells in on sheets bar 5

    Just changed it and it works fine.

    Thanks

    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