我在一个单元格中有一个date和时间值,我想使秒数为00,我该怎么做?

我有一个单元格值,例如A1 = 17/06/2016 19:00:46我想将其更改为17/06/2016 19:00:00所以基本上秒必须是0,但我似乎无法能够实现与格式化。 我做的格式为dd / mm / yyyy hh:mm,但秒数仍然保留。 我将使用这些值来匹配不同的工作表中使用Application.Match在vba中的值。 不同的表有秒为0,因此,匹配它,我需要将它们转换为0秒。 谢谢。

更简单的方法来实现这一点:

Function DateWithZeroSeconds(MyDate As Date) DateWithZeroSeconds = Format(MyDate, "dd/mm/yyyy h:m") & ":00" End Function 

select你想转换的单元格并运行这个短的macros:

 Sub SecondKiller() Dim d As Date, d2 As Date For Each r In Selection d = r.Value r.Value = DateSerial(Year(d), Month(d), Day(d)) + TimeSerial(Hour(d), Minute(d), 0) Next r End Sub 

另一种方法,格式化Excel单元格,然后将秒显示为00:

 Sub FormatRange_AsDate(ByVal Rg As Range) With Rg .NumberFormat = "d/m/yyyy h:mm:ss;@" 'give the format to the cell , showing seconds .Value = Format(.Value, "d/m/yyyy h:m") & ":00" 'changing the seconds to "00", don't use .value2 End With End Sub