Results 1 to 5 of 5

VBA to compare data in 2 sheets, issues with existing code

Threaded View

  1. #1
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    469

    VBA to compare data in 2 sheets, issues with existing code

    Hi All,

    Found some code from an old post (http://www.excelforum.com/excel-prog...ml#post3701361) which compares data in sheet1 & sheet2 and highlights differences in both sheets.

    Applied below code to my sample file (attached) but picked up some limitations which I was hoping someone could help me with:
    - Code seems to stop comparing any further once it reaches a blank cell
    - Compares dates and values relatively well but not text columns like people's names, department names, etc.
    - There also seems to be some inconsistency in comparing which i can't quite figure out

    Any help would be greatly appreciated.

    Sub Compare()
    
    Dim w1 As Worksheet, w2 As Worksheet
    Dim A1 As Range, A2 As Range
    Dim r1 As Long, r2 As Long
    
    Set w1 = Sheets("Sheet1"): Set w2 = Sheets("Sheet2")
    
    r1 = w1.Range("A" & Rows.Count).End(xlUp).Row
    r2 = w2.Range("A" & Rows.Count).End(xlUp).Row
    
    Sheet1:
    For Each A1 In w1.Range("A2:Q" & r1)
    If A1 = "" Then GoTo Sheet2
    For Each A2 In w2.Range("A2:Q" & r2)
    If A1 = A2 Then GoTo GetNext
    Next
    A1.Interior.Color = vbYellow
    GetNext: Next
    
    Sheet2:
    For Each A2 In w2.Range("A2:Q" & r2)
    If A2 = "" Then Exit Sub
    For Each A1 In w1.Range("A2:Q" & r1)
    If A1 = A2 Then GoTo GetAnother
    Next
    A2.Interior.Color = vbYellow
    GetAnother: Next
    End Sub
    Attached Files Attached Files
    Last edited by Gti182; 05-20-2014 at 02:34 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Code to compare data in 2 sheets and delete duplicates
    By amar05 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-13-2013, 03:24 PM
  2. [SOLVED] Password issues with code that protects all sheets at once
    By Paragoomba in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-10-2013, 12:57 PM
  3. [SOLVED] open a csv and compare the data with my existing worksheet.
    By sheffieldlad in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-09-2013, 07:19 AM
  4. COUNTIF Issues count blank cells among existing data
    By chrispulliam in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 05-21-2010, 01:52 AM
  5. Replies: 1
    Last Post: 08-15-2009, 05:52 AM

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