Compare Marco

lisa duncan

New Member
Joined
Jan 5, 2011
Messages
11
I need a macro to compare Columns A-H in worksheet 1
to Columns A-H in worksheet 2 move all differences to worksheet 3
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I assume they're all numbers in columns A - H in both worksheets?
Then paste onto ThisWorkbook module
Code:
Sub compareDiff()
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    Dim WS1 As Worksheet, WS2 As Worksheet, WS3 As Worksheet, LR&, i&, j&
    Set WS1 = Worksheets("Sheet1") 'Change name as required
    Set WS2 = Worksheets("Sheet2")
    Set WS3 = Worksheets("Sheet3")
     
    LR = WS1.Range("A" & Rows.Count).End(xlUp).Row
        For i = 1 To LR
            For j = 1 To 8
                'Difference between worksheet 2 and worksheet 1 (ws2 - ws1)
                WS3.Cells(i, j).Value = WS2.Cells(i, j).Value - WS1.Cells(i, j).Value
            Next j
        Next i
        
    Application.ScreenUpdating = True
    Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,763
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top