Results 1 to 8 of 8

Thread: Macro to clear data based on color fill

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    try this.

    Code:
    Sub kTest()
        
        Dim Sht     As Worksheet
        Dim LastRow As Long
        Dim LastCol As Long
        Dim rngAll  As Range
        Dim r       As Range
        Dim c       As Range
        
        On Error Resume Next
        For Each Sht In Worksheets
            With Sht
                If .UsedRange.Cells.Count > 1 Then
                    LastRow = .Cells.Find("*", .Cells(1), , 2, 1, 2).Row
                    LastCol = .Cells.Find("*", .Cells(1), , 2, 2, 2).Column
                    Set rngAll = .Range(.Cells(5, 1), .Cells(LastRow, LastCol))
                    For Each r In rngAll.SpecialCells(2, 23).Areas
                        For Each c In r.Cells
                            If c.Interior.ColorIndex <> -4142 Then
                                c.Clear 'if you want to cleat the both the formats and data
                                'c.ClearContents'removes only data
                            End If
                        Next
                    Next
                End If
            End With
        Next
                    
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  2. #2
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    14
    Thanks for the help, much appreciated

  3. #3
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    14
    Hi admin

    I would like to amend the code so that sheet 'main" is ignored when the colored data are cleared

    Your assistance is most appreciated

Similar Threads

  1. Replies: 2
    Last Post: 05-30-2013, 07:28 PM
  2. Replies: 9
    Last Post: 12-04-2012, 09:45 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 check values based on certain text
    By Howardc in forum Excel Help
    Replies: 25
    Last Post: 11-05-2012, 09:03 PM
  5. Replies: 4
    Last Post: 07-27-2012, 08:43 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
  •