+ Reply to Thread
Results 1 to 11 of 11

Comparing columns and highlighting differences

  1. #1
    Registered User
    Join Date
    08-11-2010
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2003
    Posts
    5

    Comparing columns and highlighting differences

    Hi guys

    First off! Thanks for an excellent forum. Been using it quite a bit during the last month and will continue to do so in the future.

    My first post here is about comparing the contents of different columns in a sheet. There are two sets of data that needs to be compared.

    The setup is as follows.

    Every time a factory completes an order it is shipped to a warehouse. Everytime this happens they register the outgoing shipment using a date, reference number and an amount.

    When the order is received at the warehouse they do a similar registration adding additional data as well.

    And as stated above I would like to compare the reference numbers to see if they are present. If they match I should then look at the amount registered to each reference number.

    If there are reference numbers present in either dataset my idea is to color the entire row red (or something like that).
    If the reference number is present but the amount doesn't match this line should get a different color.

    I have made a simple, not very good comparison macro, that writes directly to the sheet in a new column (not included in the current code).

    But this is a cumbersome process and I would like to think that it could be done using arrays, the find function or something similar.

    In the current code I have created two arrays containing the the information from the factory and the warehouse. Don't know if this is a step in the right direction or not but I'm hoping you guys could tell me

    Kind regards
    Michael
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Comparing columns and highlighting differences

    Michael - I can't really envisage what you're expecting the final sheet to look like. Can you elaborate, or add to your file?
    If there are reference numbers present in either dataset my idea is to color the entire row red (or something like that).
    If the reference number is present but the amount doesn't match this line should get a different color.
    The reference numbers appear to be on the same line so should they be red or another colour?

  3. #3
    Registered User
    Join Date
    08-11-2010
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Comparing columns and highlighting differences

    Yes of course!

    I will modify the workbook and upload a new version asap. This time hopefully illustrating what my intentions are

    Thank you for taking your time with this.

  4. #4
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: Comparing columns and highlighting differences

    perhaps I have not understood completely.
    the file is returned with a macro "test" in module 2. after running the macro the sheet "ark1" will look like this . Is this what you want?

    the macro is also copied here


    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Comparing columns and highlighting differences

    Avoid useing merged cells.
    I deleted the first row and then applied:

    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Comparing columns and highlighting differences

    Probably me being dense. Everyone else seems to have understood.

  7. #7
    Registered User
    Join Date
    08-11-2010
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Comparing columns and highlighting differences

    Hehe no worries, description was a bit vague

    So new workbook is uploaded, this time with a text box describing what I would like to do and the cells colored accordingly.

    Don't think I mentioned that even though both data sets are sorted it is possible for entries to occur in one set but not in the other. So a line by line comparison is not possible.

    I have added this situation to the example sheet as well.
    Best regards
    Attached Files Attached Files

  8. #8
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Comparing columns and highlighting differences

    Have you tried the two solutions already offered?

  9. #9
    Registered User
    Join Date
    08-11-2010
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Comparing columns and highlighting differences

    The first solution compares one line at a time so using the macro on the new example file it stops working if there are more entries in the one data set as far as I can tell.

    Second solution offered adds one color to row 2 and another color to the remaining rows containing data.

    What I have tried so far is to concatenate the value of the two columns in each set, write these to two new ranges in the sheet and then do a comparison of these new colums using the following code:

    Please Login or Register  to view this content.
    Just passing on the two new ranges to the private sub that uses the function IsInRange.
    The problem with this approach is speed. Comparing two ranges with approximately 10,000 rows or more takes a lot of time. First writing the two new columns and afterwards comparing the value of a single cell with each cell in the second range.

    Doing this also only paints one color if there is a mismatch and it does so in the new columns created.
    Last edited by Sejrup; 09-01-2010 at 09:25 AM.

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Comparing columns and highlighting differences

    Read all suggestions in this thread
    Avoid using merged cells.
    I deleted the first row for that reason.
    And applied this macro:
    Please Login or Register  to view this content.
    an alternative:

    Please Login or Register  to view this content.
    Last edited by snb; 09-01-2010 at 09:37 AM.

  11. #11
    Registered User
    Join Date
    08-11-2010
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Comparing columns and highlighting differences

    Sorry, missed the part with the merged cells. The last bit of code does the trick. Keep It Simple Stupid works

    Thanks for helping out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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