如何使用excel vba设置时间的小数位格式?
我正在尝试编写一个宏,它以秒(十进制)为单位获取时间值,并将其转换为mm:ss.00格式(两位小数)。最接近的是:如何使用excel vba设置时间的小数位格式?,excel,vba,Excel,Vba,我正在尝试编写一个宏,它以秒(十进制)为单位获取时间值,并将其转换为mm:ss.00格式(两位小数)。最接近的是: Application.Text((1.23 / 86400), "mm:ss.00") 其结果是: 00:01.2 我不明白为什么不显示小数点后第二位 Format()也不起作用: Format((1.23 / 86400), "mm:ss.00") 结果: 12:01.0 我在VBA中测试了上述内容,对于Application.Text((1.23/86400),“mm
Application.Text((1.23 / 86400), "mm:ss.00")
其结果是:
00:01.2
我不明白为什么不显示小数点后第二位
Format()也不起作用:
Format((1.23 / 86400), "mm:ss.00")
结果:
12:01.0
我在VBA中测试了上述内容,对于
Application.Text((1.23/86400),“mm:ss.00”)
我得到00:01.23
,对于格式((1.23/86400),“mm:ss.00”)
,我得到12:01.00
如果要将其写入Excel单元格,请执行此操作
Thisworkbook.Sheets("Sheet1").Range("A1").Value = _
"'" & Application.Text((1.23 / 86400), "mm:ss.00")
或
或者,您也可以使用此
With ThisWorkbook.Sheets("Sheet1").Range("A1")
.NumberFormat = "mm:ss.00"
.Value = Application.Text((1.23 / 86400), "mm:ss.00")
End With
或
我在VBA中测试了上述内容,对于
Application.Text((1.23/86400),“mm:ss.00”)
我得到00:01.23
,对于格式((1.23/86400),“mm:ss.00”)
,我得到12:01.00
如果要将其写入Excel单元格,请执行此操作
Thisworkbook.Sheets("Sheet1").Range("A1").Value = _
"'" & Application.Text((1.23 / 86400), "mm:ss.00")
或
或者,您也可以使用此
With ThisWorkbook.Sheets("Sheet1").Range("A1")
.NumberFormat = "mm:ss.00"
.Value = Application.Text((1.23 / 86400), "mm:ss.00")
End With
或
我们发现
Format()
VBA函数不支持第二个mm:ss.00后的小数位数。官方文件中没有提到
因此,我们没有使用Format()
函数,而是在VBA代码中调用了工作表函数TEXT()
:
TeamTime(j) = Application.WorksheetFunction.Text(thisCell, "mm:ss.00")
我们发现
Format()
VBA函数不支持第二个mm:ss.00后的小数位数。官方文件中没有提到
因此,我们没有使用Format()
函数,而是在VBA代码中调用了工作表函数TEXT()
:
TeamTime(j) = Application.WorksheetFunction.Text(thisCell, "mm:ss.00")
谢谢你,成功了。
"和
的含义是什么?它用于行继续。我也可以这样写thispoolk.Sheets(“Sheet1”).Range(“A1”).Value=“””和Application.Text((1.23/86400),“mm:ss.00”)
谢谢,这很有效。"和
的含义是什么?它用于行继续。我也可以这样写thispoolk.Sheets(“Sheet1”).Range(“A1”).Value=“””和Application.Text((1.23/86400),“mm:ss.00”)