专栏名称: 完美Excel
Excel与VBA技术学习与实践
今天看啥  ›  专栏  ›  完美Excel

VBA自定义函数:将数字转换为度分秒

完美Excel  · 公众号  · Excel  · 2024-07-21 12:22

文章预览

学习Excel技术,关注微信公众号: excelperfect 标签: VBA , 自定义函数 下面是收集自 vbaexpress.com 中的一个 VBA 自定义函数,能够将单元格中的数字转换成度分秒格式,如下图 1 所示。 图 1 VBA 程序代码如下: Function Convert_Into_HMS(Decimal_Deg As Double) As String  Dim Degrees As Long, Minutes As Long, Seconds As Double If Decimal_Deg >= 0 # Then Seconds = 3600 # * Decimal_Deg Degrees = Int(Seconds / 3600 #)    Minutes = Int((Seconds -  3600 # * Degrees) / 60#)    Seconds = Seconds -  3600 # * Degrees - 60# * Minutes    Convert_Into_HMS = Format(Degrees,  "##0" )  &  ChrW( 176 )  &  Format(Minutes,  "00" )  &   "'"   &  Format(Seconds,  "00.000" )  & "" "" Else Decimal_Deg = Decimal_Deg + 360 # Seconds = 3600 # * Decimal_Deg Degrees = Int(Seconds / 3600 #)    Minutes = Int((Seconds -  3600 # * Degrees) / 60#)    Seconds = Se ………………………………

原文地址:访问原文地址
快照地址: 访问文章快照
总结与预览地址:访问总结与预览