[Solved] Conditional Format if text is same as another cell

Discuss the spreadsheet application
Post Reply
dejador
Posts: 2
Joined: Wed Sep 08, 2021 3:19 pm

[Solved] Conditional Format if text is same as another cell

Post by dejador »

Hi,

I am making a list of unique stock codes etc for my business, and this turns into a long list.

Is there a way to check if the exact same text that I am entering in column B has already been entered earlier in the sheet?

I know I could sort it, but I am sorting by Product Name, so I just want some sort of visual alert that this code has been used before. It would always be in column B
Last edited by MrProgrammer on Thu Sep 30, 2021 10:03 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved]
Open Office 4.1.10 on Windows 10 (64 bit)
Matareuz
Posts: 23
Joined: Fri Nov 20, 2020 4:33 pm
Location: Venezuela

Re: Conditional Formatting if text is same as another cell

Post by Matareuz »

Hey,

Welcome to the forum,

I think that this could be userful for you.

viewtopic.php?f=9&t=105574&p=512564&hil ... te#p513521
LibreOffice 6.3.2.2 Windows 7 Ultimate
Mountaineer
Posts: 314
Joined: Sun Sep 06, 2020 8:27 am

Re: Conditional Formatting if text is same as another cell

Post by Mountaineer »

You may use

Code: Select all

COUNTIF(range;value)
To check only, if the code is used above, you should use a mixture of absolute and relative addressing:

Code: Select all

=COUNTIF($B$1:$B5;B5)
for a value in B5 - adapts to other rows.

So your condition may be

Code: Select all

COUNTIF($B$1:$B5;B5)>1
If this works for the single cell you may extend the range for the condition.

J

PS: You can also use validation of data.
A dialog will appear, if your condition is not met.

I use conditional formatting, if the collision just needs double checks and validation, when false values are not allowed.

PPS: A database will prevent this, if column is set UNIQUE.
OpenOffice 3.1 on Windows Vista
dejador
Posts: 2
Joined: Wed Sep 08, 2021 3:19 pm

Re: Conditional Formatting if text is same as another cell

Post by dejador »

Hi,

Thank you Matareuz but I am really not good with spreadsheets and that post just confused me even more than I already am.

~@mountaineer - =COUNTIF($B$1:$B5;B5) just turned B5 red (I have the conditional formula set up to turn the background red, am hoping if I enter a duplicate that both cells will highlight), the 2nd one didn't seem to do anything (I put the conditional formatting on B5)

I am sorry though I do not know how to extend the range? I am really quite new to all this fancy spreadsheet business and can really only do addition subtraction and multiplication formulas :D

I honestly don't know what my options are, I know it has to be a spreadsheet (working out profit margins and cost prices, so need those add subtract and multiplication cells) I just want it to alert me (and ideally highlight the duplicate cell) if I type the same code in twice, as I have quite a large stock list to go through and it will take me forever if I have to manually check each one, I thought conditional formula would work but if theres an easier way I'm all ears!
Open Office 4.1.10 on Windows 10 (64 bit)
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Conditional Formatting if text is same as another cell

Post by Villeroy »

Select the whole range you want to format conditionally so that B5 is the active input cell and apply the conditional formatting to the selected range based on the formula for B5.
Or copy B5, select the whole range, Edit>Paste-Special... formatting only.
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
User avatar
MrProgrammer
Moderator
Posts: 4905
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Conditional Formatting if text is same as another cell

Post by MrProgrammer »

Hi, and welcome to the forum.
dejador wrote:I am really quite new to all this fancy spreadsheet business and can really only do addition subtraction and multiplication formula
[Tutorial] Ten concepts that every Calc user should know
Section 8 explains why the formula below has several $ characters and why $B$2 is different than $B2.
dejador wrote:I just want some sort of visual alert that this code has been used before. It would always be in column B
To alert you if the code has been used before, in cell B3, use Conditional Format formula SUMPRODUCT($B$2:$B2=$B3) as shown in the attachment. It means "are any of the previous cells in column B equal to the current cell?"
B2, the first cell after the column headings, does not need conditional formatting since the first stock code cannot be a duplicate.
202109091109.ods
(12.79 KiB) Downloaded 116 times
[Tutorial] The SUMPRODUCT function
dejador wrote:I am sorry though I do not know how to extend the range?
Conditional formatting is considered formatting so you can enter it into the first cell where it is needed, B3. Then Edit → Copy (for B3), select the cells in column B where you want that formatting applied, say B4:B999, Edit → Paste Special → Format (uncheck everything else) → OK. You could also use the Format Paintbrush on the Standard Toolbar.
dejador wrote:… turned B5 red (I have the conditional formula set up to turn the background red, am hoping if I enter a duplicate that both cells will highlight)
No, B5 can highlight, but the previous cell cannot because there is no way for its formatting to know that B5 is now the active cell. Formula calculations cannot determine which cell is active; they only access cell values. A filter can show all of the rows where the value in column B has some specified value, or the Find command can locate values for you. Read about those suggestions in Help → Index or in User Guides (PDF) or searching for topics about them in the Calc Forum. Learning how to use filters is important if you have a long list.
dejador wrote:the exact same text
The formula will detect a duplicate if it matches exactly. Value "Foo" is different than "Foo " (with a trailing space) even though the cell contents will look identical.

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Post Reply