[英]nagging #value! error in excel udf
I am new to vb and excel but I have to develop a custom udf for excel. 我是vb和excel的新手,但我必须为excel开发自定义udf。 I have read I have tried to alter my code below many times with the suggestions on this forum to no avail. 我已经阅读过多次尝试更改此代码的内容,但对该论坛的建议无济于事。 What am I missing. 我想念什么。 This code is for working out a Julian date in integer form. 该代码用于计算整数形式的儒略日期。
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
This was able to work 这可以工作
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.