YasserKhalil
Well-Known Member
Hello everyone
I have a code that is supoosed to transfer data when a criteria is met in sheet1 and it is transferred to sheet2
This is the code
When executing the code in this case the number of results in sheet2 is 1708 rows ...
My problem is with this part (the second part of code not the first)
If I commented out the following part and execute the code I got 1987 rows
Any idea why the results are different? and which of these results are true (1708 or 1987)
Thanks advanced for help
I have a code that is supoosed to transfer data when a criteria is met in sheet1 and it is transferred to sheet2
This is the code
Code:
Sub TransferUsingArrays()
Dim a, aOutput, iCol As Long, iRow As Long, iLooper As Long, x, r As Range
Sheet2.Range("A2:L10000").ClearContents
With Worksheets("Sheet1")
a = .Range("A1").CurrentRegion
For iCol = 2 To UBound(a, 2)
If Application.WorksheetFunction.Sum(.Cells(2, iCol), .Cells(UBound(a, 1), iCol)) = 0 Then
If r Is Nothing Then
Set r = .Columns(iCol)
Else
Set r = Union(r, .Columns(iCol))
End If
End If
Next iCol
r.EntireColumn.Delete
a = .Range("A1").CurrentRegion
End With
ReDim aOutput(1 To UBound(a) * UBound(a, 2), 1 To 12)
For iCol = 2 To UBound(a, 2)
For iRow = 2 To UBound(a)
If a(iRow, iCol) > 0 Then
iLooper = iLooper + 1
aOutput(iLooper, 1) = iCol - 1
aOutput(iLooper, 3) = a(1, iCol)
aOutput(iLooper, 9) = a(iRow, 1)
aOutput(iLooper, 12) = a(iRow, iCol)
End If
Next iRow
Next iCol
Sheet2.Cells(2, "A").Resize(iLooper, 12) = aOutput
End Sub
When executing the code in this case the number of results in sheet2 is 1708 rows ...
My problem is with this part (the second part of code not the first)
Code:
r.EntireColumn.Delete
a = .Range("A1").CurrentRegion
If I commented out the following part and execute the code I got 1987 rows
Code:
a = .Range("A1").CurrentRegion
Thanks advanced for help