Compare the differences between two sheets in Excel



Compare the difference between two sheets in Excel. Highlight any differences in data between two sheets of data in Excel. Colour the cells that have changed from one sheet to another. Highlight empty cells when the other sheet had data in this location.
Check out my online courses

Code
Sub comparesheet()

Dim erowsht1, erowsht2, erow As Long
Dim ecolsht1, ecolsht2, ecol As Long
Dim row, col As Integer
row = 2
col = 1

‘find the lastrow on both sheets
erowsht1 = Sheet1.Cells(1, 1).CurrentRegion.Rows.Count
erowsht2 = Sheet2.Cells(1, 1).CurrentRegion.Rows.Count
‘which is the greater of the two that will be the end row
If erowsht2 (greater than)= erowsht1 Then
erow = erowsht2
Else
erow = erowsht1
End If
‘find the last column in both sheets
‘which ever is the larges colunn number will be the end column
ecolsht1 = Sheet1.Cells(1, 1).CurrentRegion.Columns.Count
ecolsht2 = Sheet2.Cells(1, 1).CurrentRegion.Columns.Count

If ecolsht2 (greaterthan)= ecolsht1 Then
ecol = erowsht2
Else
ecol = ecolsht1
End If

‘start with a1 and go to last row and last column in both sheets

Do Until row = erow + 1

For col = 1 To ecol + 1
If Worksheets(“Sheet1”).Cells(row, col)(does not equal)Worksheets(“Sheet2”).Cells(row, col) Then
Worksheets(“Sheet2”).Cells(row, col).Interior.ColorIndex = 7
‘Worksheets(“Sheet3”).Cells(row, col).Value = Worksheets(“Sheet2”).Cells(row, col)
End If

Next col
row = row + 1

Loop

End Sub

Check out my online courses

For more help visit my website or email me at easyexcelanswers@gmail.com.

Contact me regarding customizing this template for your needs.

Click for online Excel Consulting

I am able to provide online help on your computer at a reasonable rate.

Check out my next one-hour Excel Webinar

I use a Blue condensor Microphone to record my videos, here is the link

Check out Crowdcast for creating your webinars

If you need to buy Office 2019 follow

I use Tube Buddy to help promote my videos
Check them out

Follow me on Facebook

TWEET THIS VIDEO

Follow me on twitter
easyexcelanswers

IG @barbhendersonconsulting

You can help and generate a translation to you own language

*this description may contain affiliate links. When you click them, I may receive a small commission at no extra cost to you. I only recommend products and services that I’ve used or have experience with.

Watch more new videos about Excel Office | Synthesized by Mindovermetal English

Rate this post

Bài viết liên quan

Theo dõi
Thông báo của
guest
3 Comments
Cũ nhất
Mới nhất Được bỏ phiếu nhiều nhất
Phản hồi nội tuyến
Xem tất cả bình luận
Maria Mitova

What if You do not have it on the same row number?

MD YOUSUF

Fabulous work. Thanks a lot. It will help me a lot in office work.

Rakesh kumar Madella

Thank u