hi, experts
i got this code from the internet and i try amending what i need to creating report based on criteria col 3 = q8 it should copy theses data from sheet1 to sheet 2 but it gives me run time error 1004 "application-defined or object-defined error" in this line
Sheets("Sheet2").Range("A2").Resize(k, UBound(arr, 2)).Value = arr
this is the code
Sub report()
Dim a As Variant, arr As Variant, cTexs As Variant, cCols As Variant
Dim i As Long, j As Long, k As Long
a = Sheets("sheet1").Range("A1", Sheets("sheet1").UsedRange.SpecialCells(xlCellTypeLastCell)).Value2
cTexs = Array("CODE", "BRAND", "TYPE", "ORIGIN", "QUANTITY")
ReDim arr(1 To UBound(a, 1), 1 To UBound(cTexs) + 1)
ReDim cCols(0 To UBound(cTexs))
For j = 0 To UBound(cTexs)
cCols(j) = Application.Match(cTexs(j), Application.Index(a, 1), 0)
Next
For i = 1 To UBound(a, 2)
If a(i, cCols(0)) = "Q8" Then
k = k + 1
For j = 0 To UBound(cCols)
arr(k, j + 1) = a(i, cCols(j))
Next
End If
Next
Sheets("Sheet2").Range("A2").Resize(k, UBound(arr, 2)).Value = arr
End Sub