nguyenhuuhieu94dha
Thành viên mới

- Tham gia
- 30/10/19
- Bài viết
- 21
- Được thích
- 0
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
=CountOrderByCondition($C221;$B221; $E$221:$E$283; $C$221:$C$283; $B$221:$B$283; $E221; $H$220)

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
=CountOrderByCondition($C221;$B221; $E$221:$E$283; $C$221:$C$283; $B$221:$B$283; $E221; $H$220)
