Prevent conditional formatting overriding Number formats

Background
I have a sheet which tracks events, with their start dates in column B and start times in column C. My sheet uses conditional formatting to highlight certain values, e.g. the next event, past events etc. Because of this, I need to determine number format on a per-column basis, for example:

column B number format = D MMM
column C number format = H:MM AM/PM

Error or undesired behaviour
This works fine before I apply a conditional formatting rule to these cells. The error (or undesired behaviour) that follows occurs whether I use the Default format for all cells, and then apply my conditional format, or whether each column has its own style applied.

My conditional formatting is applied as follows:

Formula is $C2<NOW()
Range: A1:E100
Apply style: cf10

The style cf10 was created and only changes the background - to apply a grey shade.

What actually happens is that when the conditional format applies style cf10, it uses a single number format for the entire range, overriding the required distinction between cells columns B & C.

I have found a comment in the forums which starts to suggest a solution, yet does not actually provide it (user Lupp states that OP “will have created the ‘cross-out’ style”, yet does not elaborate on how to not ‘cross out’ the original style, which appears to be the default behaviour):
https://ask.libreoffice.org/t/how-to-apply-conditional-formatting-without-changing-number-format/62666/5

My LO build info
Version: 25.8.5.2 (X86_64) / LibreOffice Community
Build ID: 580(Build:2)
CPU threads: 4; OS: Linux 6.17; UI render: default; VCL: kf6 (cairo+wayland)
Locale: en-GB (en_GB.UTF-8); UI: en-US
Ubuntu package version: 4:25.8.5-0ubuntu0.25.10.1
Calc: threaded

Any help would be greatly appreciated.

If you change an attribute in a cell style then that attribute is no longer transparent and is applied. If you have already set a Number format in the cell style cf10 then go to the Numbers tab and click the button Standard to remove all the set attributes on that page, OK.
.
The sample below will recalculate every time you press F9
ConditionalFormattingOverrideCellFormat134779.ods (20.3 KB)

2 Likes

I can see how that can help in some circumstances, but I don’t think it’s quite what I want in this situation.

Because I need to apply different number formats to columns B and C, I need cf10 to respect the number format which was being applied before the conditional formatting took effect. Setting the number format of cf10 to Standard seems to tell it to inherit the Number format of cf10’s parent, which is the Default style, and apply it to all cells (if I’ve understood it correctly?)

I need to behaviour to be:
inherit the number format from the previously applied style for that cell

and whats the problem
 ( it doesnt matter the Date or time style was applied before | after CF )
date&time-styles_plus_backcolor-style_per_CF.ods (25.2 KB)

1 Like

Following on from your and EarnestAI’s advice, I created a new sheet as a Minimum Working Example and tried it again. The solution does work correctly, but frustratingly it is still not working on my working sheet. Perhaps there’s an error or corruption there which prevents it from working properly. I appreciate that will be difficult for you or anybody else to diagnose.

Here’s what I’m finding:

  • Open my MWE
  • Edit cf10
  • Numbers tab
  • Category: All
  • Format: General
  • click Standard

The Category immediately changes to select ‘Number’, and the desired output is observed.

However, in my main working sheet, when I follow these steps and click Standard, the Category immediately changes to ‘Date’. I think this might be what’s causing the error.

Furthermore, I did the same thing on the Default style (selected General > Standard) and it now also changes the date format of both columns to text, e.g. 46151.

Let’s try it. :slight_smile:
Upload the problematic example and explain what needs to be clarified.

Thanks for the offer, but as I just commented to karolus, after repeating the process over and over it eventually ‘worked’!

Im pretty sure youre »cf10« contains also an explicit Numberformat other than General⇒Standard

Edit the style and reset the number-format-tab

1 Like

You’re right, I did have a different number format.

I set it to General > Standard as you suggested, and it works correctly for column B but not column C.

In both cases, it appears to be sending the style back to the parent style from which cf10 inherits (Default) rather than the style which was applied before the conditional formatting took effect.

Okay, further to my other comment to EarnestAI, I’ve just been clicking through the styles over and over again, doing the same thing and it eventually worked. I don’t know what the issue was, but it was something to do with inheriting the number format from the Default style. It wasn’t updating with the change I made until eventually it did.

Very random, but thanks for your help. I wouldn’t have found it otherwise.

I don’t get it.
ask134779.ods (37.4 KB)
Cell style “MyDate” and “Time” with conditional style “Good” having number format “General”.

both styles have their own explicit Cell-Backcolor which are in conflict with the CellBackcolor from good 
 but resetting them to no Color doesnt solve the issue, wich seems to occur only on your ask134779.ods ??

I don’t know. Never managed to solve this issue for me.

I realise that you eventually managed to reset the Numbers tab in cf10. For future reference, look at the General tab and inspect the list of attributes changed by your style. In my sample only the background attributes of colour and transparency are applied in the conditional formatting style cf10 all other attributes can come from the original cell style.
.
If you created cf10 from Default Cell Style then maybe Default had already been altered previously