Results 1 to 3 of 3

Thread: VBA Macro To Clear Everything Excel Formula And Bold Text

  1. #1
    Member
    Join Date
    Aug 2012
    Posts
    40
    Rep Power
    0

    VBA Macro To Clear Everything Excel Formula And Bold Text

    I would like a macro to clear data on all sheets except formula, text, items in bold, values to the right of "GP % target" (the text appears in Col A and the values in Col B:M) and data that has been color filled.

    I have the following macro and have attached a sample workbook. I have also posted on Ozgrid, but the final solution I received is not working and I have not received any further reply


    Clear Data on all sheets except last 20 sheets

    In the sample data, only the first and last sheets data not to be cleared

    Your assistance in resolving this is most appreciated

    Code:
     Sub Clear_Data() 
        Dim i As Integer, r As Range 
        On Error Resume Next 
        With CreateObject("VBScript.RegExp") 
            .Pattern = "^=-?\d+(\.\d+)?([\+-/\\^\*]\d+(\.\d+)?)?$" 
            For i = 1 To Sheets.Count - 1
                For Each r In Sheets(i).UsedRange.SpecialCells(xlCellTypeFormulas) 
                    If .test(r.Formula) Then r.ClearContents 
                Next 
                For Each r In Sheets(i).UsedRange.SpecialCells(xlCellTypeConstants, 1) 
                    If Sheets(i).Cells(r.Row, 1).Value <> "GP % target" Then r.ClearContents 
                Next 
            Next 
        End With 
    End Sub

    https://www.dropbox.com/s/bodg6xsoo9...a.GP%20%25.xls
    Last edited by Flupsie; 07-03-2014 at 05:28 PM.

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    If you want to clear everything except formula, text, items in bold, values to the right of "GP % target" and data that has been color filled, what else is left? The ones you have marked with arrows, are either bold, or are formulas, or both!!
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Senior Member
    Join Date
    Apr 2012
    Posts
    193
    Rep Power
    13
    Thanks for the Reply.

    I removed this section from the code and changed GP % target to incorporate each branch for eg GP % target-Br1 , GP % target-Br2 and then set up a table and had a Vlookup in Col B and this resolved my problem

    Code:
     If Sheets(i).Cells(r.Row, 1).Value <> "GP % target" Then r.ClearContents

Similar Threads

  1. Replies: 10
    Last Post: 12-10-2012, 11:28 PM
  2. Macro To Clear Certain Data Across Many Sheets
    By Howardc in forum Excel Help
    Replies: 2
    Last Post: 12-04-2012, 09:10 AM
  3. Macro to clear data based on color fill
    By Howardc in forum Excel Help
    Replies: 7
    Last Post: 12-03-2012, 09:25 AM
  4. Excel Formula To Extract Values From Text
    By Howardc in forum Excel Help
    Replies: 1
    Last Post: 08-22-2012, 09:05 PM
  5. Need to Bold the Font of a Chart's Axes Value using VBA
    By LalitPandey87 in forum Excel Help
    Replies: 3
    Last Post: 10-06-2011, 05:18 PM

Posting Permissions

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