vba 从值范围中查找最小值和最大值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37049762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:24:03  来源:igfitidea点击:

Finding minimum and maximum values from range of values

vbarangemaxminimum

提问by Akshat Gupta

I have an excel with the following data -

我有一个包含以下数据的 excel -

Value   Date    Time
0   1-May-16    11:20 AM
0   1-May-16    12:05 PM
0   1-May-16    11:30 AM
0   5-May-16    3:40 PM
1   3-May-16    1:00 AM
1   2-May-16    1:45 AM
0   1-May-16    6:04 AM
0   4-May-16    7:09 AM
0   5-May-16    8:20 PM
2   5-May-16    1:53 AM
2   1-May-16    2:54 AM
3   1-May-16    7:35 PM
3   4-May-16    8:34 AM
4   5-May-16    2:12 PM
0   2-May-16    12:11 PM
5   1-May-16    12:45 PM
5   3-May-16    4:55 AM
5   3-May-16    1:12 AM

I need to summarize my data by value column with min and max date and time for each value.

我需要按值列汇总我的数据,每个值的最小和最大日期和时间。

The output of the above data should look like this -

上述数据的输出应如下所示 -

    Min     Max 
    Date    Time    Date    Time
0   1-May-16    11:20 AM    5-May-16    3:40 PM
1   2-May-16    1:45 AM 3-May-16    1:00 AM
2   1-May-16    2:54 AM 5-May-16    1:53 AM
3   1-May-16    7:35 PM 4-May-16    8:34 AM
4   5-May-16    2:12 PM 5-May-16    2:12 PM
5   3-May-16    1:12 AM 3-May-16    4:55 AM

Please help

请帮忙

回答by Dani Costa

try this:

尝试这个:

Set range from which to determine smallest value
Set rng = Sheet1.Range("A1:Z100")

'Worksheet function MIN returns the smallest value in a range 
dblMin = Application.WorksheetFunction.Min(rng)

From:

从:

http://www.globaliconnect.com/excel/index.php?option=com_content&view=article&id=105:find-smallest-and-largest-value-in-range-with-vba-excel&catid=79&Itemid=475

http://www.globaliconnect.com/excel/index.php?option=com_content&view=article&id=105:find-smallest-and-largest-value-in-range-with-vba-excel&catid=79&Itemid=475