Results 1 to 10 of 10

Thread: Clear Specific Rows Of Data On Multiple WorkSheets

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    14
    Hi Tony

    Thanks for the help, much appreciated

    I need the folowing change

    I need the data cleared on all the sheets, except the last two sheets-all criteria the same as before

    I have tried to do this myself, but it comes up with a compile error when activating the macro-see changes to code & asttachment

    RangeToClear = FirstColumnToClear + Format(FirstRowToClear) RangeToClear = RangeToClear + ":"

    HTML Code:
    Sub HowardsClearRoutine()
    
    Const FirstRowToClear = 4
    Const FirstColumnToClear = "A"
    Const LastColumnToClear = "D"
    Const TotalColumn = "A"
    Dim i As Long
    For i = 1 To Worksheets.Count - 2
    Dim LastRowToClear As Integer
    Dim RangeToClear As String
    Dim LocationOfTotal As Range
    Dim Sht As Worksheet
    For Each Sht In MyBook.Worksheets
    '   Find the row where the word "Total" is in column A, and clearthe contents of rows
    '   FirstRowToClear through LastRowToClear for columns FirstColumnToClear thru LastColumnToClear
    Set Sht = ActiveSheet       '   You may want to be a little more specific about this!
    
    Set LocationOfTotal = Sht.Columns(TotalColumn).Find("Total")
    '   Last row to clear is the row BEFORE the Total
    LastRowToClear = LocationOfTotal.Row - 1
    '   Now construct the range which we will be clearing
    RangeToClear = FirstColumnToClear + Format(FirstRowToClear) RangeToClear = RangeToClear + ":"
    RangeToClear = RangeToClear + LastColumnToClear + Format(LastRowToClear)
    '   Do we want to clear the contents, or delete the cells? This example simply clears the contents
    Sht.Range(RangeToClear).ClearContents
    Next i
    
    End Sub

    I have tried to amend the code to ignore the last two sheets when clearing data
    Attached Files Attached Files

Similar Threads

  1. Save Worksheets As New File To Specific Folder
    By k0st4din in forum Excel Help
    Replies: 18
    Last Post: 06-08-2013, 04:24 PM
  2. Replies: 4
    Last Post: 05-01-2013, 09:49 PM
  3. Macro To Clear Certain Data Across Many Sheets
    By Howardc in forum Excel Help
    Replies: 2
    Last Post: 12-04-2012, 09:10 AM
  4. Macro to clear data based on color fill
    By Howardc in forum Excel Help
    Replies: 7
    Last Post: 12-03-2012, 09:25 AM
  5. Replies: 2
    Last Post: 06-14-2012, 04:10 AM

Posting Permissions

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