分享

Excel中format函数用法和实例

 部落窝教育BLW 2016-04-21

第一,format函数用法介绍

  Excel VBA中format函数的用法是根据格式表达式中的指令来格式化。format函数类似于excel工作表中的text函数。format函数在VBA中经常使用到,经常使用format函数来对日期和时间进行格式化。对Excel感兴趣的朋友可加Excel学习交流群:284029260

  根据帮助,可以知道format函数的语法为:

  Format(expression[, format[, firstdayofweek[, firstweekofyear]]])

第二,format函数应用举例

format函数练习一

Sub format格式化()
    [B1] = Format(Date, "mmdd")
End Sub

  解释:将系统当天的日期,格式化为数字形式,然后再在B1单元格里显示出来。显示出来的效果:1123。

format函数练习二

Sub 现在()
    MsgBox Format(Date, "yyyy年m月") & Chr(10) & Format(Date, "AAA") & Chr(10) & Format(Now, "h") & "点"
End Sub

  解释:用消息框输出format函数格式化以后的年月、星期、时间。


    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多