在SQL Server中,MIN和MAX可以处理不对数字求值的文本,返回文本排序顺序最低或最高的文本项,或者SQL Server中已知的文本项,"整理顺序"。
是否可以在Excel中执行此操作而无需使用实际排序的UDF?
例如,对于MIN(" bb"," aa"," cc")返回" aa"和MAX( " bb"," cc"," aa")返回" cc"。
Excel的MIN / MAX忽略文本,虽然MINA / MAXA可以处理文本,但它们会破坏不能解析为数字的文本。大/小也不做。
FWIW,一位同事问我如何在一个支点中做到这一点。我没有看到自定义功能的方法。我错了吗?
答案 0 :(得分:2)
我相信你是对的,自定义功能是最好的。值得注意的是,正常的比较器运算符的工作方式与您所描述的类似。
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
答案 1 :(得分:2)
这个数组公式看起来很有希望。因为它是一个数组,所以需要用ctrl-shift-enter输入。
最大:
=INDEX(A2:A6,MATCH(0,COUNTIF(A2:A6,"<"&A2:A6),))
敏:
/**
* Print metadata for the Application Data folder.
*
* @param service Drive API service instance.
*/
private static void printApplicationDataFolderMetadata(Drive service) {
try {
File file = service.files().get("appfolder").execute();
System.out.println("Id: " + file.getId());
System.out.println("Title: " + file.getTitle());
} catch (IOException e) {
System.out.println("An error occured: " + e);
}
}
将三个范围更改为您想要的范围。