当前位置: 主页 > Office办公 > Excel专区 > Excel函数 > excel format函数用法和实例

excel format函数用法和实例

  • 2022-02-27
  • 来源/作者: 菜鸟图库/ 菜鸟图库
  • 1442 次浏览

第一,format函数用法介绍

  Excel VBA中format函数的用法是根据格式表达式中的指令来格式化。format函数类似于excel工作表中的text函数。format函数在VBA中经常使用到,经常使用format函数来对日期和时间进行格式化。

  根据帮助,可以知道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函数格式化以后的年月、星期、时间。

标签(TAG) format函数