最小/最大文本sorting顺序

在SQL Server中,MIN和MAX可以对不计算数字的文本起作用,返回文本sorting顺序最低或者最高的文本项,或者在SQL Server中称为“整理顺序”。

有没有可能在Excel中这样做,而不去实际sorting的UDF?

例如,MIN(“bb”,“aa”,“cc”)返回“aa”,MAX(“bb”,“cc”,“aa”)返回“cc”。

Excel的MIN / MAX忽略文本,尽pipeMINA / MAXA可以在文本上工作,但是它们会破坏不能parsing为数字的文本。 大/小也不要这样做。

FWIW,一位同事问我如何做到这一点。 我没有看到一个方法,没有去一个自定义函数。 我错了吗?

这个数组公式看起来很有希 因为它是一个数组,所以需要用ctrl-shift-enter进入。

马克斯:

=INDEX(A2:A6,MATCH(0,COUNTIF(A2:A6,">"&A2:A6),)) 

闵:

 =INDEX(A2:A6,MATCH(0,COUNTIF(A2:A6,"<"&A2:A6),)) 

将三个范围更改为你想要的。

我相信你是对的,自定义function是最好的。 要注意的是,正常的比较运算符的工作方式与您所描述的类似。

 Public Function MinStr(ByVal strVal As Range) As String Dim i As Integer Dim cell As Range MinStr = "" 'Check to make sure the range is not empty if strVal.Rows.Count > 0 then 'Initialize MinStr to a known value MinStr = strVal.cells(1,1).Value 'Iterate through the entire range For Each cell in strVal.Cells if(MinStr > cell.Value) then MinStr = cell.Value end if Next cell end if End Function Public Function MaxStr(ByVal strVal As Range) As String Dim i As Integer Dim cell As Range MaxStr = "" 'Check to make sure the range is not empty if strVal.Rows.Count > 0 then 'Initialize MaxStr to a known value MaxStr = strVal.cells(1,1).Value 'Iterate through the entire range For Each cell in strVal.Cells if(MaxStr < cell.Value) then MaxStr = cell.Value end if Next cell end if End Function