Hi all.
I have vba code belove to check data, Code work well if have lest than 1000 rows. But my Source data have over 50000 rows so code work very slow
Please help me to improve code to do faster. Thanks
I have vba code belove to check data, Code work well if have lest than 1000 rows. But my Source data have over 50000 rows so code work very slow
Please help me to improve code to do faster. Thanks
VBA Code:
Sub check()
dim lrow as long, cel as range, ws, wsSource, wsFault as sheet
Dim val, val1, val2, val3, val4 As Double
set wsSource = thisworkbook.sheets("Source")
Set wsFault = thisworkbook.sheets("fault")
with wsSource
For Each cel In .Range("B2:B" & lrow)
lrow = wsFault.Cells(Rows.Count, 1).End(xlUp).Row
val1 = Abs(.Cells(cel.Row, "D") + .Cells(cel.Row, "F") - .Cells(cel.Row, "H"))
val2 = Abs(.Cells(cel.Row, "E") + .Cells(cel.Row, "G") - .Cells(cel.Row, "I"))
If (val1 > 0) Or (val2) > 0 Then .Rows(cel.Row).Copy wsFault.Range("A" & lrow + 1)
If IsNumeric(Right(cel.Value, 1)) Then
.Cells(cel.Row, "C").Value = "check_Fault"
For i = 4 To 9
val = .Cells(cel.Row, i).Value - WorksheetFunction.Sum(.Range(.Cells(cel.Row + 1, i), .Cells(cel.Row + 13, i)).Value)
lrow = wsFault.Cells(Rows.Count, 1).End(xlUp).Row
If Abs(val) > 0 Then
wsFault.Range("A" & lrow + 1).Value = .Range("A" & cel.row).Value
wsFault.Range("B" & lrow + 1).Value = "Fault in column: " & .Columns(i).Address & ", rows: " & cel.Row & "_" & cel.Row + 13
end if
Next
End If
Next
' ===Finish check =========
End With
end sub