|
您好!可能是版本问题,2007版
公历转农历可以用下面函数试试。
D2=IF(C2="","",IFERROR(IF(B2="公历",gltonl(C2,7),nongli(NltoGl(C2))),"生日错误!"))
Function gltonl(valdate As Date, Optional gs As Integer = 0) As String '每当闰月的日期多一天,已经校正
'公历转农历函数 '数据校对于 2018-8-31 校对者:yzc51
Dim conDate As Date, setDate As Date, tg$, dz$, nlyear$
Dim AddMonth As Integer, AddDay As Integer, Addyear As Integer, getDay As Integer
Dim tMonth As Integer, tDay As Integer, tYear As Integer, i%
Dim RunYue As Boolean, md$, dd$, mm$, YougetDate As Date
If valdate = "0:00:00" Then Exit Function
tYear = year(valdate)
tMonth = month(valdate)
tDay = day(valdate)
On Error Resume Next
If tYear > 2200 Or tYear < 1900 Then gltonl = "": Exit Function
Call nonglibm
Addyear = tYear
RunYue = False
XUNHUAN:
AddMonth = Val(Mid(Nlbm(Addyear), 16, 1))
AddDay = Val(Mid(Nlbm(Addyear), 17, 2))
conDate = DateSerial(Addyear, AddMonth, AddDay)
setDate = DateSerial(tYear, tMonth, tDay) '***
getDay = DateDiff("d", conDate, setDate)
If getDay < 0 Then Addyear = Addyear - 1: GoTo XUNHUAN
AddDay = 1: AddMonth = 1: AddMonth1 = 1
For i = 1 To getDay
AddDay = AddDay + 1
If AddDay = 30 + Mid(Nlbm(Addyear), AddMonth1, 1) Or (RunYue And AddDay = 30 + Mid(Nlbm(Addyear), 13, 1)) Then
If RunYue = False And AddMonth = Val("&H" & Mid(Nlbm(Addyear), 14, 1)) Then
RunYue = True
AddMonth1 = AddMonth1 + 1
Else
RunYue = False
AddMonth = AddMonth + 1
AddMonth1 = AddMonth1 + 1
End If
AddDay = 1
End If
Next
md$ = "初一初二初三初四初五初六初七初八初九初十十一十二十三十四十五十六十七十八十九二十廿一廿二廿三廿四廿五廿六廿七廿八廿九三十"
dd$ = Mid(md$, (AddDay - 1) * 2 + 1, 2)
mm$ = Mid("正二三四五六七八九十冬腊", AddMonth, 1) + "月"
If RunYue Then mm$ = "闰" + mm$
tg = Mid(Tiangan$, ((Addyear - 4) Mod 10) + 1, 1)
dz = Mid(DiZhi$, ((Addyear - 4) Mod 12) + 1, 1)
nlyear = tg & dz & "年"
gltonl = nlyear + mm$ + dd$
If gs = 1 Then gltonl = Addyear & "-" & IIf(RunYue, "闰", "") & AddMonth & "-" & AddDay
If gs = 2 Then gltonl = Addyear & "年" & mm$ & dd$
If gs = 3 Then gltonl = Addyear
If gs = 4 Then gltonl = IIf(RunYue, "闰", "") & AddMonth
If gs = 5 Then gltonl = AddDay
If gs = 6 Then gltonl = Mid(ShuX$, ((Addyear - 4) Mod 12) + 1, 1)
If gs = 7 Then gltonl = "农历" & nlyear & "(" & Mid(ShuX$, ((Addyear - 4) Mod 12) + 1, 1) & ")" & mm$ + dd$
End Function
|
评分
-
1
查看全部评分
-
|