Comparing cells

Discuss the spreadsheet application
Post Reply
JasonBourne
Posts: 6
Joined: Fri Mar 14, 2008 5:09 pm

Comparing cells

Post by JasonBourne »

Hi,
I've been searching for such function / macros for ages.
Imagine you need to compare several sells values and get common values listed in separate cell. Here is the sample:
A1 = 30
A2 = 43
A3 = 35
--------
B1 = 50
B2 = 34
B3 = 35

C1 = 35 (this sell should contain a formula, not a value)
The same goes for comparing text values. To give you a better picture of why the hack do I need this function I'll tell you that I have a long list of URLs and another short one and so I need to compare them and have matching values in a third list.
User avatar
James
Volunteer
Posts: 263
Joined: Sun Oct 07, 2007 7:23 am
Location: UK

Re: Comparing sells

Post by James »

C3: =IF(A3=B3;A3;"")

Is this what you want?
James
www.8daysaweek.co.uk - A User-Focused OOo site.
Windows Easy Installation CDs & OOo on USB Keys, OOo for Mac OS X + Ubuntu CDs

Please read: Survival Guide for the forum
OOo 3.1.1 on Ubuntu 9.x + Windows XPP, Mac OS X
JasonBourne
Posts: 6
Joined: Fri Mar 14, 2008 5:09 pm

Re: Comparing sells

Post by JasonBourne »

James wrote:C3: =IF(A3=B3;A3;"")

Is this what you want?
I wish it was that simple:-) What I mean is to compare every sell from a first massive with a first sell from a second massive, then do the same for the second sell of a second massive and so on...
User avatar
James
Volunteer
Posts: 263
Joined: Sun Oct 07, 2007 7:23 am
Location: UK

Re: Comparing sells

Post by James »

Sorry I don't understand. I'm assuming you mean "cell" as in a box on a spreadsheet, not "sell"?
What is a "massive"?

Are you saying you want to compare cell A1 in 2 separate spreadsheets? Your example in your first post suggested comparing values in 2 columns (A & B):
JasonBourne wrote:Imagine you need to compare several sells values and get common values listed in separate cell. Here is the sample:
A1 = 30
A2 = 43
A3 = 35
--------
B1 = 50
B2 = 34
B3 = 35

C1 = 35 (this sell should contain a formula, not a value)
The same goes for comparing text values.
How long is your list of values?
James
www.8daysaweek.co.uk - A User-Focused OOo site.
Windows Easy Installation CDs & OOo on USB Keys, OOo for Mac OS X + Ubuntu CDs

Please read: Survival Guide for the forum
OOo 3.1.1 on Ubuntu 9.x + Windows XPP, Mac OS X
JasonBourne
Posts: 6
Joined: Fri Mar 14, 2008 5:09 pm

Re: Comparing sells

Post by JasonBourne »

Ok, I guess it's because of it's Friday:-) Yes, I mean cell, not sell:-).
I'm gonna give you a more illustrative sample to clarify the whole thing.

I need to compare cell values on a single sheet.

A1 = http://www.google.com
A2 = http://www.yahoo.com
A3= http://blah-blah.com

B1 = http://www.Iguessnowitlooksbetter.com
B2 = http://www.yahoo.com
B3 = http://www.thanksgoditsfridayalready.com

C1 = http://www.yahoo.com (formula)

I'm talking about several thousands values in A column and several hundreds in B column and I need to have matching values for the column A and B at column C
User avatar
James
Volunteer
Posts: 263
Joined: Sun Oct 07, 2007 7:23 am
Location: UK

Re: Comparing sells

Post by James »

JasonBourne wrote:C1 = http://www.yahoo.com (formula)
Is that C1 or should it / could it be C2?
James
www.8daysaweek.co.uk - A User-Focused OOo site.
Windows Easy Installation CDs & OOo on USB Keys, OOo for Mac OS X + Ubuntu CDs

Please read: Survival Guide for the forum
OOo 3.1.1 on Ubuntu 9.x + Windows XPP, Mac OS X
JasonBourne
Posts: 6
Joined: Fri Mar 14, 2008 5:09 pm

Re: Comparing sells

Post by JasonBourne »

Well I'm giving a sample where there is only one match, but it's possible to have several and I want to have them listed in column C.
User avatar
James
Volunteer
Posts: 263
Joined: Sun Oct 07, 2007 7:23 am
Location: UK

Re: Comparing sells

Post by James »

That (the answer to my Q) doesn't matter as much as - how automated do you want this to be?

For instance, using the formula I pasted above, you could:
  1. Drag that down the entire sheet
  2. Copy column C and paste values into column D
  3. Sort column D to remove blanks
But obviously steps 2 & 3 are manual in this method. If you need this to be done via a macro, then I suggest you ask nicely in the Macros and UNO API forum ;).
James
www.8daysaweek.co.uk - A User-Focused OOo site.
Windows Easy Installation CDs & OOo on USB Keys, OOo for Mac OS X + Ubuntu CDs

Please read: Survival Guide for the forum
OOo 3.1.1 on Ubuntu 9.x + Windows XPP, Mac OS X
JasonBourne
Posts: 6
Joined: Fri Mar 14, 2008 5:09 pm

Re: Comparing cells

Post by JasonBourne »

Well, now I'm sitting at home with my Macbook on my laps and trying your suggestion ;)

1. Ok, I think you still can't get my point:-) A formula which I want to place on column C should do the following:
Compare Every cell from column A with a first cell from column B. Keep in mind that it's possible that identical to B1 cell value could be located in ANY cell of a column A, from A1 to An, where n - is a given number of cells for a particular case

2.After comparing the first cell of a column B with every single cells value in column A do the same with the second cell of a column B (B2) and so on


Thanks a lot for your help! 8-)
User avatar
James
Volunteer
Posts: 263
Joined: Sun Oct 07, 2007 7:23 am
Location: UK

Re: Comparing cells

Post by James »

JasonBourne wrote:A formula which I want to place on column C should do the following:
Compare Every cell from column A with a first cell from column B.
Ah! Now I understand :idea: Will need to think on this for a while.
James
www.8daysaweek.co.uk - A User-Focused OOo site.
Windows Easy Installation CDs & OOo on USB Keys, OOo for Mac OS X + Ubuntu CDs

Please read: Survival Guide for the forum
OOo 3.1.1 on Ubuntu 9.x + Windows XPP, Mac OS X
User avatar
James
Volunteer
Posts: 263
Joined: Sun Oct 07, 2007 7:23 am
Location: UK

Re: Comparing cells

Post by James »

Does it matter whether there are repeated values e.g. if the value in B1 appears 3 times in Column A?
James
www.8daysaweek.co.uk - A User-Focused OOo site.
Windows Easy Installation CDs & OOo on USB Keys, OOo for Mac OS X + Ubuntu CDs

Please read: Survival Guide for the forum
OOo 3.1.1 on Ubuntu 9.x + Windows XPP, Mac OS X
Dave
Posts: 1011
Joined: Sun Dec 23, 2007 6:53 pm

Re: Comparing cells

Post by Dave »

Example:

I have this in columns A and B:

q s
w t
e f
r u
t h
y o
u k
I
o
p
a
s
d
f
g
h
j
k

In C1, I put this: =IF(ISNA(OFFSET(A1;MATCH(B1;$A$1:$A$19;0)-1;0));"No Match";OFFSET(A1;MATCH(B1;$A$1:$A$19;0)-1;0))
Copy down column C.

With an "s" in B1, I got an "s" in C1. With anything not in the list of column A, I got "No match".

David.
User avatar
James
Volunteer
Posts: 263
Joined: Sun Oct 07, 2007 7:23 am
Location: UK

Re: Comparing cells

Post by James »

OK one way to do it, similar to the method I posted before, is to use:
=IF(ISNA(VLOOKUP(B1;$A$1:$A$65536;1;0))=1;"No match";VLOOKUP(B1;$A$1:$A$65536;1;0))

If you enter this formula in Column D it will tell you if the value is unique or not:
=IF(COUNTIF($A$1:$A$65536;C1)>1;COUNTIF($A$1:$A$65536;C1);"")

HTH,
 Edit: Changed hyphen to "No match" so that result is similar to Dave's post 
James
www.8daysaweek.co.uk - A User-Focused OOo site.
Windows Easy Installation CDs & OOo on USB Keys, OOo for Mac OS X + Ubuntu CDs

Please read: Survival Guide for the forum
OOo 3.1.1 on Ubuntu 9.x + Windows XPP, Mac OS X
JasonBourne
Posts: 6
Joined: Fri Mar 14, 2008 5:09 pm

Re: Comparing cells

Post by JasonBourne »

It does work!!!!
Thanks James, you've saved tons of my time!!!!
Last edited by JasonBourne on Sat Mar 15, 2008 12:00 am, edited 2 times in total.
User avatar
James
Volunteer
Posts: 263
Joined: Sun Oct 07, 2007 7:23 am
Location: UK

Re: Comparing cells

Post by James »

No problem :)
James
www.8daysaweek.co.uk - A User-Focused OOo site.
Windows Easy Installation CDs & OOo on USB Keys, OOo for Mac OS X + Ubuntu CDs

Please read: Survival Guide for the forum
OOo 3.1.1 on Ubuntu 9.x + Windows XPP, Mac OS X
specialsymbol
Posts: 4
Joined: Thu Feb 05, 2009 3:16 pm

Re: Comparing cells

Post by specialsymbol »

I'm right now trying to find a macro that does this for only one column- find identical values/strings in different cells of the same column. Doesn't work by now, but I'm still trying.

Ok, found the solution:
I got the german version of OpenOffice.Org.

The parameters are all in german, as IF becomes WENN, COUNTIF becomes VERGLEICH and so on.

This formula does work:

Code: Select all

=WENN(VERGLEICH(J1;$J$1:$J$65536;1)=ZEILE(J1);"";VERGLEICH(J1;$J$1:$J$65536))
It will deliver the last line where the identical value of the given line is found. When there is no identical line, nothing will be shown.
OOo 3.0.X on Ms Windows XP
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Comparing cells

Post by acknak »

I'm probably missing something important, but doesn't this do what you want?
Attachments
common.ods
(9.43 KiB) Downloaded 208 times
AOO4/LO5 • Linux • Fedora 23
Post Reply