我是vb和excel的新手,但我必须为excel开发自定义udf。我已经阅读过我已尝试多次修改我的代码,但是这个论坛上的建议无济于事。我错过了什么此代码用于以整数形式计算Julian日期。
Option Explicit
Function CUSTOMJULIAN(JYear As Integer, JMonth As Integer, JDay As Integer) As Integer
Application.Volatile
Dim iyear As Integer
iyear = JYear
Dim imonth As Integer
imonth = JMonth + 1
If imonth <= 2 Then
iyear = iyear - 1
imonth = imonth + 12
End If
CUSTOMJULIAN = Int(365.25 * iyear) + Int(30.6001 * imonth) + JDay + 1720995
If JDay + (31 * (JMonth + 12 * JYear)) >= (15 + (31 * (10 + 12 * 1582))) Then
Dim iadjustment As Integer
iadjustment = Int(0.01 * iyear)
CUSTOMJULIAN = CUSTOMJULIAN + 2 - iadjustment + Int(0.25 * iadjustment)
End If
End Function
答案 0 :(得分:0)
替换以下行
If JDay + (31 * (JMonth + 12 * JYear)) >= (15 + (31 * (10 + 12 * 1582))) Then
到
If JDay + (31 * (JMonth + 12 * JYear)) >= (15 + (31 * (10 + 12 * CLng(1582)))) Then
查看详情here。
答案 1 :(得分:0)
这是可以工作的
Option Explicit
Function CUSTOMJULIAN(JYear As Integer, JMonth As Integer, JDay As Integer) As Long
Dim iyear As Long
iyear = JYear
Dim imonth As Long
imonth = JMonth + 1
If imonth <= 2 Then
iyear = iyear - 1
imonth = imonth + 12
End If
CUSTOMJULIAN = Int(365.25 * iyear) + Int(30.6001 * imonth) + JDay + 1720995
Dim iday As Long
iday = 12 * JYear
iday = iday + JMonth
iday = iday * 31
If iday >= 588829 Then
Dim iadjustment As Long
iadjustment = Int(0.01 * iyear)
CUSTOMJULIAN = CUSTOMJULIAN + 2 - iadjustment + Int(0.25 * iadjustment)
End If
End Function