+ Reply to Thread
Results 1 to 10 of 10

Matching positive to negative values

  1. #1
    Registered User
    Join Date
    09-10-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    17

    Matching positive to negative values

    Hi guys!

    I was wonding if you could help me? I need a macro in VBA that will go through column Q, and highlight values that are exact opposites

    I.e.
    1000
    123
    456
    888
    -856
    564
    856
    -1000
    669
    -123
    333

    Thanks everyone, I really appreciate it!

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Matching positive to negative values

    You could easily do this with Conditional Formatting instead...

    select column Q, go to Home|Conditional Formatting|New Rule

    Use a formula to determine which cells to format

    enter formula: =COUNTIF(Q:Q,-Q1)

    click Format and choose colour from Font tab
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    09-10-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Matching positive to negative values

    Hi NBVC,

    That work perfectly! However it is highlighting the all of the value that match perfectly, what i need is if a value has been matched, it can not link to another value.

    For example

    1000
    3500
    6500
    1586
    1000
    -1000
    3698
    1000
    3654
    -3654

    Here there are 3 positive 1000's and 1 negative 1000, so one +1000 and one -1000 are highlighted and the other two stay the same

    Thanks!

  4. #4
    Valued Forum Contributor
    Join Date
    05-08-2012
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2003, 2010
    Posts
    811

    Re: Matching positive to negative values

    Assuming your list is in cells A1:A11

    Set a CONDITIONAL FORMAT rule with this equation

    =IF(ISERROR(IF(A1=VLOOKUP(-1*A1,$A$1:$A$11,1,FALSE),,)),FALSE,TRUE)

    Copy this CONDITIONAL FORMAT rule down using COPY and PASTE SPECIAL format
    Click on star (*) below if this helps

  5. #5
    Registered User
    Join Date
    09-10-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Matching positive to negative values

    Hi K m,

    I still have the same problem that it is matching all of the exact values, rather than if a value has already been matched, it is not matched again....

    Thanks!

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Matching positive to negative values

    Try:

    =AND(COUNTIF(Q$1:Q1,Q1)=1,COUNTIF(Q:Q,-Q1))

  7. #7
    Registered User
    Join Date
    09-10-2012
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Matching positive to negative values

    Hi NBVC,

    Thats nearly it. It has highlighted most of the values, however it seems to have missed a few....

    I have attached the numbers here in a spreadsheet to help. note that these are only the figures, and not the whole speadsheet. in the original spreadsheet, this column is from column Q.

    Thanks!

    Book2.xlsx

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Matching positive to negative values

    Can you identify which should/shouln't be hightlighted and why?

  9. #9
    Registered User
    Join Date
    03-07-2017
    Location
    Philippines
    MS-Off Ver
    2013
    Posts
    5

    Re: Matching positive to negative values

    Hi NBVC,

    I make it much broad,

    let say this is the table: Already match the positive and negative value

    ID____Number: Value____Code____Company Name_____Date
    1____(-1409810.28)____VJ______Company 1_____Day 2
    2____1409810.28 ______VJ______Company 1_____Day 2
    3____469747.8 ______RN______Company 1_____Day 2
    4____(-469747.8) ______RN______Company 2_____Day 2
    5____(-78291.3) ______RN______Company 3_____Day 5
    6____78291.3_________RN_______Company 3_____Day 5
    7____(-38915.52)______VJ______Company 8_____Day 3
    8____38915.52________VJ______Company 8________Day 3
    9____(-14102.48)______SY______Company 1______Day 3
    10____14102.48_______SY______Company 2_______Day 2

    As you can see ID 1 and 2 have the same Number value = to zero. Highlight row to green when Company Name and date is the same "example ID 1 Company is the same to ID 2 company, Also in date
    and ID 3 and 4 highlight row into yellow when their company name and date is different to each other.
    and as you see in ID 9 and 10 has Code is SY highlight it into blue when it is SY, and the Number value is = to zero

    Hope you help us. Many thanks in advance
    Last edited by alfie22; 03-08-2017 at 09:57 PM.

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,944

    Re: Matching positive to negative values

    alfie22 welcome to the forum

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1