Hello. Could someone walk me through with a LOT of of detail what this code is doing and what each piece of the code means? Thanks!!
Sub comparevalues()
Dim sws, dws As Worksheet
Dim rng, rng1, cell As Range
Dim lr As Long
Dim n As Integer
Set sws = ThisWorkbook.Sheets("Sheet1")
Set dws = ThisWorkbook.Sheets("Sheet2")
sws.Activate
lr = sws.Cells(Rows.Count, 2).End(xlUp).Row
Set rng = sws.Range("B2:B" & lr)
Set rng1 = sws.Range("P2:P" & lr)
Application.ScreenUpdating = False
sws.Range("B1:C1").Copy dws.Range("A1")
sws.Range("P1:Q1").Copy dws.Range("C1")
For Each cell In rng
On Error Resume Next
n = WorksheetFunction.Match(cell, rng1, 0)
If Err = 0 Then
If cell.Offset(0, 1) <> Cells(n + 1, "Q") Then
Cells(n + 1, "R") = "Wrong Amount"
cell.Resize(1, 2).Copy dws.Range("A" & Rows.Count).End(3)(2)
Cells(n + 1, "P").Resize(1, 2).Copy dws.Range("C" & Rows.Count).End(3)(2)
End If
End If
Err = 0
Next cell
Columns("R:S").AutoFit
Application.ScreenUpdating = True
End Sub
Bookmarks