- Tham gia
- 23/3/16
- Bài viết
- 705
- Được thích
- 52
Function TSGN(CSDL As Range, Optional Num As Integer = 13)
Dim sRng As Range, WF As Object
Dim Max_ As Integer, Min_ As Integer, J As Integer
Set WF = Application.WorksheetFunction
Max_ = WF.Max(CSDL): Min_ = WF.Min(CSDL)
If Num > Max_ Then
TSGN = Max_: Exit Function
End If
If Num < Min_ Then
TSGN = "Nothing!": Exit Function
End If
For J = Num To Min_ Step -1
Set sRng = CSDL.Find(J, , xlFormulas, xlWhole)
If Not sRng Is Nothing Then
TSGN = J: Exit Function
End If
Next J
End Function
Thử:
=AGGREGATE(14,6,(C4:C12<=E4)*C4:C12,1)
Rỗi việc viết để bạn nào muốn tham khảo:
PHP:Function TSGN(CSDL As Range, Optional Num As Integer = 13) Dim sRng As Range, WF As Object Dim Max_ As Integer, Min_ As Integer, J As Integer Set WF = Application.WorksheetFunction Max_ = WF.Max(CSDL): Min_ = WF.Min(CSDL) If Num > Max_ Then TSGN = Max_: Exit Function End If If Num < Min_ Then TSGN = "Nothing!": Exit Function End If For J = Num To Min_ Step -1 Set sRng = CSDL.Find(J, , xlFormulas, xlWhole) If Not sRng Is Nothing Then TSGN = J: Exit Function End If Next J End Function
Function TSGN(CSDL As Range, Optional Num As Integer = 35)
Dim sRng As Range, WF As Object
Dim Max_ As Integer, Min_ As Integer, J As Integer
Set WF = Application.WorksheetFunction
Max_ = WF.Max(CSDL): Min_ = WF.Min(CSDL)
If Num > Max_ Then
TSGN = Max_: Exit Function
End If
If Num < Min_ Then
TSGN = Min_: Exit Function
End If
For J = Num To Max_
Set sRng = CSDL.Find(J, , xlFormulas, xlWhole)
If Not sRng Is Nothing Then
TSGN = J: Exit Function
End If
Next J
End Function
Công thức anh vô cùng chính xác. Em cảm ơn anh rất nhiều. Trường hợp tìm số >= ( Lớn hoặc bằng số cần tìm ) em có đổi lại sao nó không hiểu anh =AGGREGATE(14,6,(C4:C120>=E4)*C4:C120,1)
=AGGREGATE(15,6,C4:C120/(C4:C120>=E4),1)
Theo tôi công thức không chính xác.Công thức anh vô cùng chính xác.