I wrote a VBA code to compare the content of two sheets containing order information for my company. Here's what I'm trying to accomplish
- If the order is in the new sheet but not the old sheet, highlight the entire row in the new sheet.
- If order information on an existing order has changed from the old sheet (ex. delivery date), highlight the changed cell in the new sheet.
Below is my code but the For Loop keeps crashing after 1000 rows...I feel like my code is inefficient. I'm new to Excel VBA so I would really appreciate any help.
Private Sub test()
Sheets("New Sheet").Select
Row = 2
Cells(Row, 1).Select
Dim cell As Range
Dim BigCell As Range
For i = 1 To 3000
If Not IsEmpty(ActiveCell.Offset(0, 2)) Then 'Run check if Column C is not blank
PIModel = ActiveCell.Value
Sheets("Old Sheet").Select
Columns("A:A").Select
Set findPIModel = Selection.Find(What:=PIModel, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If (findPIModel Is Nothing) Then
Sheets("New Sheet").Select
ActiveCell.Columns("A:X").Interior.ColorIndex = 37
Row = Row + 1
Cells(Row, 1).Select
Else
findPIModel.Activate
'Skipping a few columns because I don't need to run check on all of them
Column = 19
Columnoffset = 18
For Each cell In Sheets("New Sheet").Range("A1:P1")
If Not Worksheets("New Sheet").Cells(Row, Column).Value = ActiveCell.Offset(0, Columnoffset).Value Then
Worksheets("New Sheet").Select
Cells(Row, Column).Interior.ColorIndex = 37
Column = Column + 1
Columnoffset = Columnoffset + 1
Worksheets("Old Sheet").Select
Cells(Row, 1).Select
End If
Next
Row = Row + 1
Sheets("New Sheet").Select
Cells(Row, 1).Select
End If
Else: Exit For
End If
Next i
End Sub