+ Reply to Thread
Results 1 to 11 of 11

To compare two excel sheets and colour changed cells

  1. #1
    Registered User
    Join Date
    03-20-2014
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    9

    To compare two excel sheets and colour changed cells

    The VB macro (below) I tried to adapt for my use is not working. I generate excel report from an application which is updated by different teams in my organisation; it will be very silly of me to be asking every team what they have updated. I want my macro to:
    1) arrange all the columns of the new excel report generated as my old excel sheet i.e mirror my old excel sheet.
    2) use 2 specific columns (site A and site B columns) from my old excel report (with several other columns) to compare with the new excel report; if there is any new or updated row/column on the new excel report the macro should colour the cells of any row/column that has changed.

    These reports will be different workbooks.

    Sub Report()

    Dim varSheetA As Range
    Dim varSheetB As Range
    Dim strRangeToCheck As String
    Dim iRow As Long
    Dim iCol As Long

    strRangeToCheck = "A1:IV65536"
    ' If you know the data will only be in a smaller range, reduce the size of the ranges above.
    Debug.Print Now
    varSheetA = Worksheets("Sheet1").Range(strRangeToCheck)
    varSheetB = Worksheets("Sheet2").Range(strRangeToCheck) ' or whatever your other sheet is.
    Debug.Print Now

    For iRow = LBound(varSheetA, 1) To UBound(varSheetA, 1)
    For iCol = LBound(varSheetA, 2) To UBound(varSheetA, 2)
    If varSheetA(iRow, iCol) = varSheetB(iRow, iCol) Then
    ' Cells are identical.
    ' Do nothing.
    Else
    ' Cells are different.
    ' Code goes here for whatever it is you want to do.
    End If
    Next iCol
    Next iRow

    End Sub
    I will appreciate your help on this.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: To compare two excel sheets and colour changed cells

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    03-20-2014
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: To compare two excel sheets and colour changed cells

    To compare two excel sheets and colour changed cells



    The VB macro (below) I tried to adapt for my use is not working. I generate excel report from an application which is updated by different teams in my organisation; it will be very silly of me to be asking every team what they have updated. I want my macro to:
    1) arrange all the columns of the new excel report generated as my old excel sheet i.e mirror my old excel sheet.
    2) use 2 specific columns (site A and site B columns) from my old excel report (with several other columns) to compare with the new excel report; if there is any new or updated row/column on the new excel report the macro should colour the cells of any row/column that has changed.

    Updated cells are highlighted in yellow on Workbook named NEW.

    These reports are on different workbooks.

    Please Login or Register  to view this content.
    I will appreciate your help on this.
    Attached Files Attached Files

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: To compare two excel sheets and colour changed cells

    Hi TorHor,

    Here's my code but it highlights a lot of cells:

    Please Login or Register  to view this content.
    Obviously - you'll need to change the book names

  5. #5
    Registered User
    Join Date
    03-20-2014
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: To compare two excel sheets and colour changed cells

    Thanks but I was getting 'subscript out of range' error when I tried to use it on both excel sheets. What else can I do?

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: To compare two excel sheets and colour changed cells

    Hi ToyHor,

    Obviously - you'll need to change the book names

  7. #7
    Registered User
    Join Date
    03-20-2014
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: To compare two excel sheets and colour changed cells

    Yes, it was after I changed the book names that I received that error. What else should I try? Thanks. I appreciate your help.

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: To compare two excel sheets and colour changed cells

    Are the Sheets named REPORT 1 and REPORT 2

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: To compare two excel sheets and colour changed cells

    It's probably the extensions:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    03-20-2014
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: To compare two excel sheets and colour changed cells

    Thanks, guys, it worked. My mistake, I missed out spaces in the names of my sheet. Apologies.

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: To compare two excel sheets and colour changed cells

    You're welcome!

+ 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. Replies: 11
    Last Post: 05-03-2013, 05:49 AM
  2. Macro that clears contents of all cells of certain colour (colour 35) in all sheets
    By Hanskubansku in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-25-2012, 07:33 AM
  3. Compare cells in two worksheets and copy the changed rows to a new sheet
    By vbvamsi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-01-2012, 05:25 PM
  4. Replies: 3
    Last Post: 12-30-2011, 02:17 PM
  5. How can I Compare cells to find a price but allow the value to be changed.
    By connor8392 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-04-2010, 07:18 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