Option Explicit
Sub muna()
Dim s1 As Worksheet, s2 As Worksheet
Set s1 = Sheets("Data dump")
Set s2 = Sheets("Results page")
Dim i As Long, lr As Long, lrR As Long
Application.ScreenUpdating = False
lr = s1.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To lr
lrR = s2.Range("A" & Rows.Count).End(xlUp).Row
With s1
If .Range("A" & i) <> .Range("B" & i) Or .Range("C" & i) <> .Range("D" & i) Or .Range("E" & i) <> .Range("F" & i) Then
.Range("A" & i & ":F" & i).Copy s2.Range("A" & lrR + 1)
End If
End With
Next i
Application.CutCopyMode = False
Application.ScreenUpdating = True
MsgBox "Complete"
End Sub
Code:Option Explicit Sub muna() Dim s1 As Worksheet, s2 As Worksheet Set s1 = Sheets("Data dump") Set s2 = Sheets("Results page") Dim i As Long, lr As Long, lrR As Long Application.ScreenUpdating = False lr = s1.Range("A" & Rows.Count).End(xlUp).Row For i = 2 To lr lrR = s2.Range("A" & Rows.Count).End(xlUp).Row With s1 If .Range("A" & i) <> .Range("B" & i) Or .Range("C" & i) <> .Range("D" & i) Or .Range("E" & i) <> .Range("F" & i) Then .Range("A" & i & ":F" & i).Copy s2.Range("A" & lrR + 1) End If End With Next i Application.CutCopyMode = False Application.ScreenUpdating = True MsgBox "Complete" End Sub
Standard Module
How to install your new code
Copy the Excel VBA code
Select the workbook in which you want to store the Excel VBA code
Press Alt+F11 to open the Visual Basic Editor
Choose Insert > Module
Edit > Paste the macro into the module that appeared
Close the VBEditor
Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)
To run the Excel VBA code:
Press Alt-F8 to open the macro list
Select a macro in the list
Click the Run button
P.S. Should there be a colon next to F?
.Range("A" & i & ":F" & i)
What function does the colon do?
Thank you and everyone else for their help.The statement says the range A to F in row i. You need the colon in a manner similar to =Sum(A1:C1) which provides a sum of Cells A1, B1 and C1
Name Refers to
Correct = (Table1[Original name]=Table1[Actual name]) * (Table1[Original team]=Table1[Final team]) * (Table1[Original directorate]=Table1[Final directorate])
Error_count = SUM( 1 - Correct )
Error_record = SMALL( IF( NOT(Correct), Record_number ), Record_number )
Record_number = ROW(Table1) - 1
= SUMPRODUCT( N(Table1[Original name]<>Table1[Actual name]) ) / ROWS(Table1)
This has a formula-based solution as well.
It may look strange but it works!
Code:Name Refers to Correct = (Table1[Original name]=Table1[Actual name]) * (Table1[Original team]=Table1[Final team]) * (Table1[Original directorate]=Table1[Final directorate]) Error_count = SUM( 1 - Correct ) Error_record = SMALL( IF( NOT(Correct), Record_number ), Record_number ) Record_number = ROW(Table1) - 1
Worksheet formulas for the percentage error are of the form
Code:= SUMPRODUCT( N(Table1[Original name]<>Table1[Actual name]) ) / ROWS(Table1)
Thank you.I apologize. The workbook was meant to show a formula alternative to the Power Query solution. Unfortunately I moved the data range at the last moment before posting and did not notice that my formula for 'record_number' was
= ROW(Table1) - 1
rather than the more robust
= ROW(Table1) - ROW(Table1[#Headers])
The ticks and crosses are simply conditionally formatted [0, 1] which shows the content of the named array 'correct' which refers to the formula
= (Table1[Original name]=Table1[Actual name])
* (Table1[Original team]=Table1[Final team])
* (Table1[Original directorate]=Table1[Final directorate])
As it stands such an array formula would need to be extended by selecting the larger region and reentering the formula using CSE.
To make the values extend with the table one would require a non-array formula that is part of the table, as shown below. Since the formula for compacting the error rows is an array formula, I have used the new column 'OK?'
=Table1[OK]
to rebuild the formulas for 'Error_count' and 'Error_record'
= SUM( 1 - OK? )
= SMALL( IF( NOT(OK?), Record_number ), Record_number )
Thank you.I hit 'Post Reply' prematurely. I have now edited the post to include the updated file.
Apologies.The attached contains a table showing team stats on how many rows were reassigned.