+ Reply to Thread
Results 1 to 22 of 22

Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

  1. #1
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    Do not run the following code. It is left here for instructional purposes to demonstrate how it developed into a working macro. There are details in my next Code I posted that elaborate on what improvements were made and why for speed and functionality purposes.

    Please Login or Register  to view this content.
    Last edited by joe31623; 01-09-2016 at 01:24 AM.
    <---If my answer helped, please click *

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    you may try this code
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Registered User
    Join Date
    01-24-2014
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    OK, so this definitely works, but is there a way to do this so I don't end up without any grid lines?

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    "grid lines" can be referring to many things. There is a feature of Excel called the Macro Recorder. Start a macro recording, remove the grid lines to match your desired output, stop the recording, then you will have your code.
    If you are happy with my response please click the * in the lower left of my post.

  5. #5
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    Yasser -- Thank you!

    Matt,

    I updated the following code so it doesn't take so long to run, it practically crashes Excel. I reduced the number of cells the macro loops over to exactly the cells that are used. I am still unable to display the gridlines and I'll update this again if I figure that out.

    Anyone Viewing this thread: Do not run the following code. It is left below for instructional purposes. You can see the difference between this and the next code as to why this vs the other code takes so long to run. The addition of the parameter: LastColumnInRow and the loop over Rows instead of all cells in the range were key to speeding this up to practical runtimes with practical memory resources.
    Please Login or Register  to view this content.
    Last edited by joe31623; 01-09-2016 at 01:22 AM.

  6. #6
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    FINALLY!!!! Thanks to YasserKhalil and gbeats101, we got it! The following solution will not crash excel (I'm running 2015 excel w/ 8GB of RAM on a 64 bit operating system), completes the task when I loop over thousands of cells in less than 3s, and DOES NOT hide grid lines (they were there all along, but not visible because any interior color at all hides the gridlines and the .DisplayFormat.Interior.Color method seemed to be returning a color so slight that it was not detectable).

    Your solution, sir:

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    Slightly Off Topic:

    mattsonberg asked:
    is there a way to do this so I don't end up without any grid lines?
    When setting the Interior Color of a cell, all colors except 'None' remove the grid lines. 'None' can only be used with 'ColorIndex' to the best of my knowledge. I had to experiment a little to match the Default Gridline Colors that are in my version of Excel 2003 and Excel 2010. Your default gridline colors may vary.

    See the following example code which is included in the attached file:
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    Thank you, LJ. Not off-topic as well. Actually, I spent about two hours trying to figure that out.
    Last edited by joe31623; 01-09-2016 at 08:57 PM.

  9. #9
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    Latest modification:
    Please Login or Register  to view this content.
    Last edited by joe31623; 01-10-2016 at 01:33 PM.

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    Hi Joe
    I tried to comapre the code posted in post #6 and your last code in post #9 to find the difference but I couldn't find any difference
    What is the new modification in Post #9?
    Regards

  11. #11
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    Please note that the .DisplayFormat construction will only work in Excel 2010+.

    There are other more involved solutions for prior Excel Versions such as:
    http://www.get-digital-help.com/2013...ted-cells-vba/
    http://www.mrexcel.com/forum/excel-q...our-cells.html
    http://www.mrexcel.com/forum/excel-q...ormatting.html
    http://www.excelfox.com/forum/f22/ge...ng-or-not-338/

    In addition, I recommend against using numbers such as 1677215 in favor of either one of the built in Excel Constants: https://msdn.microsoft.com/en-us/lib...=vs.60%29.aspx
    vbBlack
    vbRed
    vbGreen
    vbYellow
    vbBlue
    vbMagenta
    vbCyan
    vbWhite

    When using other colors my personal preference is to create pseudo-constants using RGB, since RGB can not be used in a constant. For example:

    In an ordinary code module ModGlobals:
    Please Login or Register  to view this content.
    Here is a simple example that uses the code. Each Sub that uses a color should call the Initialize routine, otherwise there is a chance that the color Pseudo-Constant will Not be initialized and will have a value of 0 (ZERO) which is BLACK.
    Please Login or Register  to view this content.
    Lewis
    Last edited by LJMetzger; 01-10-2016 at 08:20 AM.

  12. #12
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    Yasser,

    The difference is very subtle. Aside from the recent edit to substitute vbWhite and 16777215, I used .Interior.ColorIndex = xlNone in post 9 instead of .Interior.Color = xlNone. That includes LJMetzger's contribution; although, .Interior.Color seems to work for Excel 2015.

    LJMetzger,

    Thanks again for going above and beyond with your contribution to this thread! You've inspired another question I'll try to figure out myself or post as a new topic.

    Joe

  13. #13
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    Also will be better to only process cells with conditional formats - for this you may use specialcells.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  14. #14
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    Per https://msdn.microsoft.com/en-us/lib.../ff196157.aspx I see options:

    XlCellType constants
    Value
    xlCellTypeAllFormatConditions. Cells of any format
    -4172
    xlCellTypeAllValidation. Cells having validation criteria
    -4174
    xlCellTypeBlanks. Empty cells
    4
    xlCellTypeComments. Cells containing notes
    -4144
    xlCellTypeConstants. Cells containing constants
    2
    xlCellTypeFormulas. Cells containing formulas
    -4123
    xlCellTypeLastCell. The last cell in the used range
    11
    xlCellTypeSameFormatConditions. Cells having the same format
    -4173
    xlCellTypeSameValidation. Cells having the same validation criteria
    -4175
    xlCellTypeVisible. All visible cells
    12

    ...I'm not quite sure which would return conditional formats. Is this an incomplete list? If not, which wold you use, Izandol?

  15. #15
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    xlcelltypeallformatconditions is correct one.

  16. #16
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    Thanks!

    For the curious reader as novice as I: http://www.mrexcel.com/forum/excel-q...onditions.html

  17. #17
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    Excellent point Izandol.

    To implement the Special Cells try code like:
    Please Login or Register  to view this content.
    Lewis

  18. #18
    Registered User
    Join Date
    01-24-2014
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    Quote Originally Posted by joe31623 View Post
    Latest modification:
    Please Login or Register  to view this content.
    When I run this macro the message at the end says that it was using the range $a$1:$t$486... why isn't it working with the whole sheet? It should be running through something like $a$1:$nc$12000 based on my data. Any suggestions?

  19. #19
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    LastColumnOfRow = R.Cells(R.Row, LastColumn + 1).End(xlToLeft).Column should have been used instead of
    LastColumnOfRow = R.Cells(R.Row, LastColumn).End(xlToLeft).Column.

    See below:
    Please Login or Register  to view this content.
    That should work and I'd like to know if it doesn't. I would expect LJMetzger's code (that I've adapted to your case below) works more quickly. LJMetzger took Izandol's idea of only looping through cells in the Used range that have conditional formatting and took care of the error that would occur if there is no conditional formatting on a worksheet. For that reason, the above code is not as efficient as the following.

    Please Login or Register  to view this content.
    *Corrected to include "With R/End With" in the above code at 5:53 PM (EST) on 1/11/2016
    *Added an "If Not Rng Is Nothing/End If" in the above code at 6:01 PM (EST) on 1/11/2016 else there would probably be a runtime error if Rng is set to nothing due to a case where there is no conditional formatting in a worksheet.
    Last edited by joe31623; 01-11-2016 at 11:04 PM.

  20. #20
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    My speculation is that the following may be incorrect, and that both should be either 'Color' or 'ColorIndex.
    Please Login or Register  to view this content.

  21. #21
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    I think you're right. http://answers.microsoft.com/en-us/o...1ad1d17?auth=1

    The code will be updated w/I 5min.

  22. #22
    Registered User
    Join Date
    01-24-2014
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: Answered Question: How To Keep Color Of Cells And Delete Conditional Formatting

    Wow. I can't thank you guys enough for sticking this one out with/for me! This last macro works perfectly. Kudos on a job well done!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Conditional Formatting - Color Formatting for Blank Cells
    By mlbdc2012 in forum Excel General
    Replies: 10
    Last Post: 02-10-2015, 06:28 AM
  2. Replies: 3
    Last Post: 05-30-2014, 10:24 AM
  3. [SOLVED] Conditional formatting to color only cells in one row
    By nivoe in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-11-2012, 05:54 AM
  4. Using Conditional Formatting: If cells contain, then color to?
    By davelarue in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-02-2012, 02:22 AM
  5. Replies: 6
    Last Post: 12-28-2009, 02:40 AM
  6. Replies: 4
    Last Post: 06-14-2009, 03:10 AM
  7. Replies: 6
    Last Post: 03-22-2005, 01:06 PM

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