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ự 3/SN, 4/SN, 5/SN.

Liên hệ QC
Tôi tuân thủ nội quy khi đăng bài

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)

z5329089057083_6fb82332434b793df3f3904c14757166.jpg
 
Tốt hơn bạn đưa file lên; Đưa cái hình lên thì làm ăn được gì cơ chứ?!
 
Upvote 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)

View attachment 300114
Đăng bài kiểu cụ của cao thủ vô duyên.
 
Upvote 0
1000/1000 là mình sẽ không giúp trường hợp vừa viết tắt, vừa không có chào hỏi câu nào cả.
k phải đâu do mình đính kèm mãi k đk
Bài đã được tự động gộp:

Tốt hơn bạn đưa file lên; Đưa cái hình lên thì làm ăn được gì cơ chứ?!
Do mình tìm mãi k thấy nút đình kèm file. Giờ có bình luận nó mới hiện ra nút đính kèm file
 

File đính kèm

  • 1. HC Trung tâm hành chính.xlsb
    1.4 MB · Đọc: 4
Upvote 0
=CountOrderByCondition($C221;$B221; $E$221:$E$283; $C$221:$C$283; $B$221:$B$283; $E221; $H$220)
Hàm này cần cung cấp 2 tham biến là $C221;$B221 ;
Nhưng hiên trên trang 'NhatKi' chúng đang rỗng;
& như vậy câu lệnh này trong hàm
Mã:
 '. . . . . . '
If customValueC = "" And customValueB = "" Then
CountOrderByCondition = ""
Exit Function
End If
'. . . . '
Thì sao biết hàm này làm việc ra sao? Hay bạn thích đùa, nhỉ?
 
Upvote 0
Web KT
Back
Top Bottom