Public Sub hello67(targetWS As Worksheet, Optional ByVal endDate As Variant, _
Optional ByVal startRow As Integer = 5, Optional ByVal startCol As String = "C")
Dim lr As Long, arr As Variant, r As Long, c As Long, k As Long, arrRS As Variant, today As Variant
lr = Sheet8.UsedRange.SpecialCells(xlCellTypeLastCell).Row
arr = Sheet8.Range("C8:AM" & lr).Value
today = Format(Date, "yyyyMMdd")
If IsMissing(endDate) Then endDate = Sheet8.[AM8].Value
If IsEmpty(endDate) Then endDate = -1
ReDim arrRS(1 To 500000, 1 To 6)
For r = 2 To UBound(arr) Step 1
If arr(r, 4) = "Stock" Then
If InStr(arr(r, 3), "Assy") > 0 Then
If IsNumeric(arr(r, 2)) Then
If arr(r, 2) > 0 Then
For c = 6 To UBound(arr, 2) Step 1
If arr(1, c) <= endDate Then
If IsNumeric(arr(r, c)) Then
If arr(r, c) > 0 Then
k = k + 1
arrRS(k, 1) = arr(r, 1)
arrRS(k, 2) = 1111000570
arrRS(k, 3) = arr(1, c)
arrRS(k, 4) = arr(1, c)
arrRS(k, 5) = arr(r, c)
arrRS(k, 6) = today
End If
End If
End If
Next
End If
End If
End If
End If
Next
With targetWS
lr = WorksheetFunction.Max(.Range(startCol & startRow - 1).CurrentRegion.SpecialCells(xlCellTypeLastCell).Row, startRow)
.Range(startCol & startRow & ":" & startCol & lr).Resize(, 6).ClearContents
If k > 0 Then .Range(startCol & startRow).Resize(k, 6) = arrRS
End With
End Sub