Hello. I want to copy data from Sheet1 to Sheet2 provided that there is a zero value from the column F to N The row is discarded and the rest copied. The following code just checks column F I want to ignore the row only if there is zero value in all cells
VBA Code:
Sub CopyData()
Dim x, y(), i As Long, ii As Long, iii As Long
Dim lr As Long
Set st = Sheets("sheet1")
Set WS = Sheets("résultat")
lr = st.Range("D" & Rows.Count).End(xlUp).Row
lr2 = WS.Range("A" & Rows.Count).End(xlUp).Row
x = st.Range("D1:N" & lr)
For i = 1 To UBound(x, 1)
If x(i, 3) <> 0 Then
iii = iii + 1: ReDim Preserve y(1 To UBound(x, 2), 1 To iii)
For ii = 1 To UBound(x, 2)
y(ii, iii) = x(i, ii)
Next
End If
Next
With Sheets("résultat")
WS.Range("a2:k" & lr2).ClearContents
.[a1].Resize(iii, UBound(y, 1)) = Application.Transpose(y)
End With
End Sub