如何使用VBA在日期列中查找最新日期 [英] How to find the most recent date in a date column using VBA
问题描述
我有一列日期链接到其他数据,我对它们的排序方式感到满意.因此,在不对excel工作表中的数据进行排序的情况下,我需要在该列中找到最新日期和最旧日期.
I have a column of dates which are linked to other data and I am happy with how they are sorted. So without sorting the data in the excel sheet I need to find the most recent and the oldest dates in that column.
到目前为止,我有以下代码并没有帮助.
I have had the following code so far which are not that helpful.
Max_date = Application.WorksheetFunction.Max(Columns("X")).Value
MsgBox Max_date
谢谢高
推荐答案
从第一行代码中删除".value".
Remove ".value" from your first line of code.
Max_date = Application.WorksheetFunction.Max(Columns("X"))
MsgBox Max_date
这将返回代表Microsoft Excel日期时间代码中日期的数字.
This returns the number that represents the date in Microsoft Excel date-time code.
要回应Scott Craner的评论,请使用以下命令显示数字的日期格式版本.
To echo Scott Craner's comment, use the following to display the date formatted version of the number.
Max_date = Application.WorksheetFunction.Max(Columns("X"))
MsgBox cDate(Max_date)
这篇关于如何使用VBA在日期列中查找最新日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!