Nhờ các bác giúp e sửa đoạn code VBA sau

HHHHH

Yêu THVBA
Mình trả công 100K gọi là công giúp đỡ. Nhờ các bác sửa giúp e code vba sau với các dữ liệu ngày 26/10/2022 giống nhau sẽ được đếm theo thứ tự 2/SN, 3/SN, 4/SN, 5/SN.
Link file:

=CountOrderByCondition($C221;$B221; $E$221:$E$283; $C$221:$C$283; $B$221:$B$283; $E221; $H$220)
Function CountOrderByCondition(customValueC As Variant, customValueB As Variant, DateRange As Range, AmountRangeC As Range, AmountRangeB As Range, DateValueD As Variant, TextData As Range) As Variant
Dim count As Long
Dim i As Long
Dim checkDate As Date
Dim previousCount As Long

If customValueC = "" And customValueB = "" Then
CountOrderByCondition = ""
Exit Function
End If

If customValueC > 0 And customValueB = 0 Then
count = 0
checkDate = DateValueD
For i = 1 To DateRange.Rows.count
If DateRange.cells(i, 1).Value < checkDate And AmountRangeC.cells(i, 1).Value > 0 Then
count = count + 1
ElseIf DateRange.cells(i, 1).Value = checkDate And AmountRangeC.cells(i, 1).Value > 0 Then
previousCount = count
count = previousCount + 1
End If
Next i
CountOrderByCondition = count & TextData.Value
Exit Function
End If

If customValueC = 0 And customValueB > 0 Then
count = 0
checkDate = DateValueD
For i = 1 To DateRange.Rows.count
If DateRange.cells(i, 1).Value < checkDate And AmountRangeB.cells(i, 1).Value > 0 Then
count = count + 1
ElseIf DateRange.cells(i, 1).Value = checkDate And AmountRangeB.cells(i, 1).Value > 0 Then
previousCount = count
count = previousCount + 1
End If
Next i
CountOrderByCondition = count & TextData.Value
Exit Function
End If

CountOrderByCondition = ""
End Function
 
Sửa lần cuối:
Top