Conditional formatting, comparing two columns

Discuss the spreadsheet application
Post Reply
blueskyy
Posts: 2
Joined: Fri May 01, 2015 10:37 pm

Conditional formatting, comparing two columns

Post by blueskyy »

I am at my wit's end.

I have two columns of numbers. Column A and Column B, we'll call them.

I need to look at each number/cell in Column B, compare it to the matching number/cell in Column A. If B>=A, then turn green. If B<A, then turn red.

HOW do I do this? I have tried everything I can think of. x.x
OpenOffice 4.1.1 on Windows 8
User avatar
Zizi64
Volunteer
Posts: 11505
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: conditional formatting, comparing two columns

Post by Zizi64 »

First, you need create two cell styles, named (for example) 'Red', and 'Green' based on the default cell style.
Then adjust the properties of the created cellstyles (background color and/or text color)
Finally use the 'Conditional format' option, and set the conditions and the cell styles for the TRUE result...
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Villeroy
Volunteer
Posts: 31363
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: conditional formatting, comparing two columns

Post by Villeroy »

1) Create the 2 cell styles with red and green color.
2) Select the cells you want to format conditionally, say A1:B999. At this point it is very important to notice the address of the active input cell within the selection, say B999.
3) Apply one of the 2 styles, say "Green"
3) Format>Conditional...
<Value is> <Formula Is>: $B999<$A999 and choose the red style.

Like any other formula expression with mixed references, this formula reads: THIS ROW's value in $B < THIS ROW's value in $A and THIS refers to the currently active cell $B999

How to debug a conditional formatting formula:
Select some unused cell range of equal dimensions, say Y1:Z999, and enter your conditional formatting formula with Alt+Enter instead of enter. This will fill the selected cell range with the formula entered into the active cell and you will see which cells get a FALSE or TRUE value.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
blueskyy
Posts: 2
Joined: Fri May 01, 2015 10:37 pm

Re: conditional formatting, comparing two columns

Post by blueskyy »

Okay, so by default I made them all green and am focusing on how to get the "less than" cells to turn red.

_A_ _B_
.50 .20
.50 .30
.20 .50
.20 .30

Say this is my table. I need the first two cells in column B to turn red (since .20 and .30 are less than .50) but the other two cells can stay green (since .50 and .30 are greater than .20)

What cells do I select? I tried the formula Villeroy posted but that only affects one cell at a time.

EDIT - So I selected both columns but now both columns have red cells if B<A ... getting closer...
OpenOffice 4.1.1 on Windows 8
User avatar
Villeroy
Volunteer
Posts: 31363
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: conditional formatting, comparing two columns

Post by Villeroy »

You select A1:A4 and the important thing to notice is the active input cell. Of course you need to know what absolute, relative and mixed references are.
[Tutorial] Absolute, relative and mixed references
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply