macro error

lisa duncan

New Member
Joined
Jan 5, 2011
Messages
11
I have a macro that should compare two worksheets; then any differences should be put on a third worksheet. The worksheets are very large and the range is from colums A to H and the rows are from 1 to 62512 on the second sheet and 1 to 60118 on the first sheet

Below is the macro when I run it I get an error of 400

Any help would be greatly appreciated!

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

If WS2.Cells(i, j).Text <> WS1.Cells(i, j).Text Then
WS3.Cells(i, j).Text = WS2.Cells(i, j).Text & " <> " & WS1.Cells(i, j).Text
End If
Next j
Next i

Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
 
When I run you code , sheet 3 returns nothing, unless I explicitly alter a value. Sound as if there's something else in your cells, you could try removing spaces as below.
Code:
If Trim(WS2.Cells(i, j).Text) <> Trim(WS1.Cells(i, j).Text) Then
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,224,620
Messages
6,179,925
Members
452,949
Latest member
beartooth91

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