Private Sub UserForm_Activate()
code
End Sub
Sub progress(pctCompl As Single)
UserForm_Progress.lblText.Caption = pctCompl & "% completed"
UserForm_Progress.lblBar.Width = pctCompl * 2
DoEvents
End Sub
Sub code()
Dim n As Long
Dim colsBK As Range
Dim colsBKCell As Range
Dim answer As Variant
Dim i As Integer
Dim pctCompl As Single
On Error GoTo 0
For i = 0 To 100 Step 20 'i is the progressbar percentage indicator. I use Step 20 to speed up the progress, but ideally this should be step 1
'*****************************************************************************************
'STAGE 1 compare the figures in columns B to K with the corresponding cells in Sheet OLD
'*****************************************************************************************
n = 0 'n is the number of differences
Set colsBK = Range("B2", Range("B65536").End(xlUp).Offset(0, 9))
For Each colsBKCell In colsBK
If Not colsBKCell.Value = Sheets("old").Cells(colsBKCell.Row, colsBKCell.Column).Value Then
colsBKCell.Interior.ColorIndex = 3
n = n + 1
Else
colsBKCell.Interior.ColorIndex = 0
End If
Next colsBKCell
pctCompl = i
progress pctCompl
Next i
'*****************************************************************************************
'STAGE 2 If n>0 then ask for reset
'*****************************************************************************************
If n > 0 Then
answer = MsgBox("Reset figures ?", vbYesNo)
If answer = vbNo Then
Unload UserForm_Progress
Exit Sub
Else
Application.ScreenUpdating = False
For Each colsBKCell In colsBK
colsBKCell.Value = Sheets("old").Cells(colsBKCell.Row, colsBKCell.Column).Value
colsBKCell.Interior.ColorIndex = 0
Next colsBKCell
Application.ScreenUpdating = True
MsgBox ("Reset completed"), vbInformation
End If
Else
End If
MsgBox (n & " differences")
Unload UserForm_Progress
End Sub