Preserve conditional formatting on cut-paste

4

1

I have some data from different sources that I'm trying to line up to get a good handle on which fields they have in common and which they don't. To make it easier to see rows, I set up a conditional formatting rule like this:

Rule:

=MOD(ROW(),2)=0

Applies to:

=$1:$1048576

Action:

Turn Green

This works great... until I cut and paste a block of cells in one column or another. Excel's "intelligent cut-and-paste" breaks everything, by either duplicating rules, or removing sections from the region, and I have to go fix the conditional formatting again. How can I move the data around without changing the coniditional formatting rules?

durron597

Posted 2013-09-24T13:49:19.827

Reputation: 479

1

Possible duplicate of Excel conditional formatting fragmentation

– Fabian Schmied – 2019-01-03T08:24:18.107

Answers

3

I managed to find one solution, I recorded this macro:

Sub FomattingRules()
'
' FomattingRules Macro
'
' Keyboard Shortcut: Ctrl+e
'
    Cells.Select
    Cells.FormatConditions.Delete

    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=MOD(ROW(),2)=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent3
        .TintAndShade = 0.599963377788629
    End With
    Selection.FormatConditions(1).StopIfTrue = False
End Sub

Technically this works but I'd rather find a solution that doesn't require me to press ctrl+e every so often. But it's better than resetting the rules by hand, I guess.

durron597

Posted 2013-09-24T13:49:19.827

Reputation: 479

1

Not being as talented of a programmer as some of you are, what I did to solve the problem is a short two step process. first, I created one additional line of data separate from the data field I am working on for my project. I made sure that this data line has the correct conditional formatting I want to use across the entire data field. For convenience, I titled this line "Standard".

Next, I simply select the "Standard" line by highlighting all of the cells which have the formula of which I wish to copy. Third, I use the "format painter" function. I click "format painter" (upper left corner of the screen below cut and copy), and then highlight the cells that I want the formula to match the formula preserved in the "Standard" line.

It isn't automatic, but once you create the "Standard" line preserving the conditional formatting you want to use, it is very easy to apply to even a very large data field in just two steps.

Bill Kesatie

Posted 2013-09-24T13:49:19.827

Reputation: 11

1

There's no great way to get around this. I recommend doing Copy+Paste Values, then deleting the contents of the original cells. This will leave all formatting unchanged, but move cell contents successfully. It's a little cumbersome, but your other option is to redo the Conditional Formatting every time you cut and paste. You decide which is less work.

irockyoursocks

Posted 2013-09-24T13:49:19.827

Reputation: 73

Given my macro, I think doing that is less work. But thanks for confirming there's no good way to do this! – durron597 – 2013-09-24T21:00:40.093

@durron597 I agree. I just wanted to share an alternative. My suggestion preserves all conditional formattings. While yours totally works for the OP, others may be unhappy that the macro deletes ALL conditional formattings, then applys only the one that is built into the macro. Just different. – irockyoursocks – 2013-09-24T21:10:51.760

-1

Locking cells is not a solution, tested and does not work!

If you Paste using "Paste Special - no formatting", this will not break already formatted cells, and you don't have to worry about your user having to turn on Macros in order to fix the formatting. Easy fix/workaround for already deployed solutions!

user703269

Posted 2013-09-24T13:49:19.827

Reputation: 1

How is this different than irockyoursocks' answer? – durron597 – 2017-03-02T20:54:25.483

It is different as I encourage the use of PASTE SPECIAL-No Formatting. which irockyoursocks doesn't mention. DETAILS! – user703269 – 2017-04-06T18:35:25.650

-1

This is very inelegant, but also very quick, and seems to work perfectly as far as I can tell...

Copy your conditionally-formatted cells, paste them into a Word document, copy the cells from the Word document, paste them into the target Excel sheet.

tomOd

Posted 2013-09-24T13:49:19.827

Reputation: 1

-1

I had the same problem and found a little workaround - maybe usable for you:

Instead of copy & paste: mark the last row/column (or range) and use Fill Down/Fill Right action (Shortcut: strg+< / strg+>). Then the formatting is also transferred.

This can also be done with macro, i.e. for a row range:

Range("D2:D15").Select
Selection.FillDown

Instead of cut & paste: select the row or column and MOVE it by hover the cursor to the edge of the selection (the cross with arrows cursor appears) and drag & drop the row/column incl. pressing SHIFT. Then it is not a classic cut & paste, but moving. The condition formatting should be kept.

Chris

Posted 2013-09-24T13:49:19.827

Reputation: 182

1FYI: Strg is Ctrl in German layout. And the shortcut for fill down/fill right is ctrl+D/ctrl+R respectively – phuclv – 2015-12-08T06:47:07.667

1Fill down/right isn't a good substitute for cut+paste, and drag-to-move also moves my conditional formatting – Dan Cecile – 2016-11-24T17:58:20.947

-1

I found a new way to do this!

You lock the cells that are conditionally formatted. When you cut and paste, the conditional formatting stays the same!

Frankie P

Posted 2013-09-24T13:49:19.827

Reputation: 1

6Congratulations on your discovery. Can you edit your answer to share the details of how to lock the cells that are conditionally formatted? – fixer1234 – 2015-03-03T20:38:12.463

1I would be likely to upvote and even accept this answer if you edit it as described by @fixer1234 – durron597 – 2015-03-04T01:35:25.190

-2

I think it's a matter of how you search for the answer. This worked for me perfectly: https://www.extendoffice.com/documents/excel/3686-excel-remove-conditional-formatting-but-keep-format.html#a1

Josh

Posted 2013-09-24T13:49:19.827

Reputation: 1