+ Reply to Thread
Results 1 to 6 of 6

VBA Compare rows and highlight the difference

  1. #1
    Registered User
    Join Date
    05-03-2019
    Location
    New York
    MS-Off Ver
    Office 365
    Posts
    3

    Question VBA Compare rows and highlight the difference

    Hi,

    Can anyone please help me write a VBA code to compare Cost for each SKU at different whse locations and highlight If there is any difference in the cost. Jump to the next SKU range and iterate the process.

    Sample table is below:

    SKUNum WhseLocation Cost
    A132 1-10 1
    A132 2-10 1
    A132 3-10 1
    A133 1-10 0.5
    A133 2-10 0.5
    A133 3-10 1
    A134 1-10 2
    A134 2-10 1
    A134 3-10 0.5

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: VBA Compare rows and highlight the difference

    You can highlight the values in the table by using Conditional formatting, with the formula option. Select your table starting with A2, and apply CF with your choice of color using the formula

    =COUNTIF($A:$A,$A2)<>COUNTIFS($A:$A,$A2,$C:$C,$C2)
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    05-03-2019
    Location
    New York
    MS-Off Ver
    Office 365
    Posts
    3

    Re: VBA Compare rows and highlight the difference

    Hi Bernie,

    This doesn't work. It's not highlighting any of the cells where the cost differs for the same SKU.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: VBA Compare rows and highlight the difference

    You made a mistake, then, modifying my formula for your actual workbook. Here is a working example.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-03-2019
    Location
    New York
    MS-Off Ver
    Office 365
    Posts
    3

    Re: VBA Compare rows and highlight the difference

    Thanks Bernie, this document was helpful but this highlights all the SKU's that was different cost at different locations.
    Is there anyway It can highlight only the location which has different cost.
    For Ex - In the sample table, For SKU A133, It should only highlight the row with location 3-10 which has different value than the other 2 locations for this SKU.

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: VBA Compare rows and highlight the difference

    You could try the formula

    =AND(COUNTIF($A:$A,$A2)<>COUNTIFS($A:$A,$A2,$C:$C,$C2),COUNTIFS($A:$A,$A2,$C:$C,$C2)=1)

    It will work for A133, but will also highlight the three different values for A134 - unless you have some other logical requirement.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Compare Column and highlight difference
    By Barieq in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-30-2017, 07:35 AM
  2. [SOLVED] Compare 2 columns with 1 column and highlight difference
    By pradeepdeepu_001 in forum Excel General
    Replies: 3
    Last Post: 12-15-2016, 02:11 AM
  3. vba macros to compare 2 worksheets and highlight the difference
    By hecgroups in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-13-2015, 11:16 AM
  4. Compare Two Columns and Highlight the Difference
    By VickyVykciV in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-25-2014, 01:21 AM
  5. Replies: 5
    Last Post: 01-06-2012, 04:15 AM
  6. [SOLVED] Compare strings in cells and highlight difference
    By Odin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-28-2006, 05:20 AM
  7. [SOLVED] How do you compare 2 list of numbers and highlight the difference
    By Jay Jones in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-20-2006, 12:50 PM

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