Excel自定义求农历函数――nongli(公历日期,显示序号)

合集下载

公历转农历EXCEL宏讲解

公历转农历EXCEL宏讲解

Public Function NongLi(Optional XX_DATE As Date)Dim MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11), ShuXiang(11), DayName(30), MonName(12)Dim curTime, curYear, curMonth, curDayDim GongliStr, NongliStr, NongliDayStrDim i, m, n, k, isEnd, bit, TheDate'»ñÈ¡µ±Ç°ÏµÍ³Ê±¼äcurTime = XX_DATE'Ìì¸ÉÃû³ÆTianGan(0) = "¼×"TianGan(1) = "ÒÒ"TianGan(2) = "±û"TianGan(3) = "¶¡"TianGan(4) = "Îì"TianGan(5) = "¼º"TianGan(6) = "¸ý"TianGan(7) = "ÐÁ"TianGan(8) = "ÈÉ"TianGan(9) = "¹ï"'µØÖ§Ãû³ÆDiZhi(0) = "×Ó"DiZhi(1) = "³ó"DiZhi(2) = "Òú"DiZhi(3) = "î"DiZhi(4) = "³½"DiZhi(5) = "ËÈ"DiZhi(6) = "Îç"DiZhi(7) = "δ"DiZhi(8) = "Éê"DiZhi(9) = "ÓÏ"DiZhi(10) = "Ðç"DiZhi(11) = "º¥"'ÊôÏàÃû³ÆShuXiang(0) = "Êó"ShuXiang(1) = "Å£"ShuXiang(2) = "»¢"ShuXiang(3) = "ÍÃ"ShuXiang(4) = "Áú"ShuXiang(5) = "Éß"ShuXiang(6) = "Âí"ShuXiang(7) = "Ñò" ShuXiang(8) = "ºï" ShuXiang(9) = "¼¦" ShuXiang(10) = "¹·" ShuXiang(11) = "Öí" 'Å©ÀúÈÕÆÚÃûDayName(0) = "*" DayName(1) = "³õÒ»" DayName(2) = "³õ¶þ" DayName(3) = "³õÈý" DayName(4) = "³õËÄ" DayName(5) = "³õÎå" DayName(6) = "³õÁù" DayName(7) = "³õÆß" DayName(8) = "³õ°Ë" DayName(9) = "³õ¾Å" DayName(10) = "³õÊ®" DayName(11) = "ʮһ" DayName(12) = "Ê®¶þ" DayName(13) = "Ê®Èý" DayName(14) = "Ê®ËÄ" DayName(15) = "Ê®Îå" DayName(16) = "Ê®Áù" DayName(17) = "Ê®Æß" DayName(18) = "Ê®°Ë" DayName(19) = "Ê®¾Å" DayName(20) = "¶þÊ®" DayName(21) = "Ø¥Ò»" DayName(22) = "Ø¥¶þ" DayName(23) = "Ø¥Èý" DayName(24) = "Ø¥ËÄ" DayName(25) = "Ø¥Îå" DayName(26) = "Ø¥Áù" DayName(27) = "Ø¥Æß" DayName(28) = "Ø¥°Ë" DayName(29) = "Ø¥¾Å" DayName(30) = "ÈýÊ®" 'Å©ÀúÔ·ÝÃûMonName(0) = "*" MonName(1) = "Õý" MonName(2) = "¶þ" MonName(3) = "Èý" MonName(4) = "ËÄ" MonName(5) = "Îå"MonName(6) = "Áù" MonName(7) = "Æß" MonName(8) = "°Ë" MonName(9) = "¾Å" MonName(10) = "Ê®" MonName(11) = "ʮһ" MonName(12) = "À°"'¹«ÀúÿÔÂÇ°ÃæµÄÌìÊý MonthAdd(0) = 0 MonthAdd(1) = 31 MonthAdd(2) = 59 MonthAdd(3) = 90 MonthAdd(4) = 120 MonthAdd(5) = 151 MonthAdd(6) = 181 MonthAdd(7) = 212 MonthAdd(8) = 243 MonthAdd(9) = 273 MonthAdd(10) = 304 MonthAdd(11) = 334'Å©ÀúÊý¾ÝNongliData(0) = 2635 NongliData(1) = 333387 NongliData(2) = 1701 NongliData(3) = 1748 NongliData(4) = 267701 NongliData(5) = 694 NongliData(6) = 2391 NongliData(7) = 133423 NongliData(8) = 1175 NongliData(9) = 396438 NongliData(10) = 3402 NongliData(11) = 3749 NongliData(12) = 331177 NongliData(13) = 1453 NongliData(14) = 694 NongliData(15) = 201326 NongliData(16) = 2350 NongliData(17) = 465197 NongliData(18) = 3221 NongliData(19) = 3402 NongliData(20) = 400202 NongliData(21) = 2901 NongliData(22) = 1386NongliData(24) = 605 NongliData(25) = 2349 NongliData(26) = 137515 NongliData(27) = 2709 NongliData(28) = 464533 NongliData(29) = 1738 NongliData(30) = 2901 NongliData(31) = 330421 NongliData(32) = 1242 NongliData(33) = 2651 NongliData(34) = 199255 NongliData(35) = 1323 NongliData(36) = 529706 NongliData(37) = 3733 NongliData(38) = 1706 NongliData(39) = 398762 NongliData(40) = 2741 NongliData(41) = 1206 NongliData(42) = 267438 NongliData(43) = 2647 NongliData(44) = 1318 NongliData(45) = 204070 NongliData(46) = 3477 NongliData(47) = 461653 NongliData(48) = 1386 NongliData(49) = 2413 NongliData(50) = 330077 NongliData(51) = 1197 NongliData(52) = 2637 NongliData(53) = 268877 NongliData(54) = 3365 NongliData(55) = 531109 NongliData(56) = 2900 NongliData(57) = 2922 NongliData(58) = 398042 NongliData(59) = 2395 NongliData(60) = 1179 NongliData(61) = 267415 NongliData(62) = 2635 NongliData(63) = 661067 NongliData(64) = 1701 NongliData(65) = 1748 NongliData(66) = 398772NongliData(68) = 2391NongliData(69) = 330031NongliData(70) = 1175NongliData(71) = 1611NongliData(72) = 200010NongliData(73) = 3749NongliData(74) = 527717NongliData(75) = 1452NongliData(76) = 2742NongliData(77) = 332397NongliData(78) = 2350NongliData(79) = 3222NongliData(80) = 268949NongliData(81) = 3402NongliData(82) = 3493NongliData(83) = 133973NongliData(84) = 1386NongliData(85) = 464219NongliData(86) = 605NongliData(87) = 2349NongliData(88) = 334123NongliData(89) = 2709NongliData(90) = 2890NongliData(91) = 267946NongliData(92) = 2773NongliData(93) = 592565NongliData(94) = 1210NongliData(95) = 2651NongliData(96) = 395863NongliData(97) = 1323NongliData(98) = 2707NongliData(99) = 265877'Éú³Éµ±Ç°¹«ÀúÄê¡¢Ô¡¢ÈÕ ==> GongliStrcurYear = Year(curTime)curMonth = Month(curTime)curDay = Day(curTime)GongliStr = curYear & "Äê"If (curMonth < 10) ThenGongliStr = GongliStr & "0" & curMonth & "ÔÂ" ElseGongliStr = GongliStr & curMonth & "ÔÂ"End IfIf (curDay < 10) ThenGongliStr = GongliStr & "0" & curDay & "ÈÕ"ElseGongliStr = GongliStr & curDay & "ÈÕ"End If'¼ÆËãµ½³õʼʱ¼ä1921Äê2ÔÂ8ÈÕµÄÌìÊý£º1921-2-8(ÕýÔ³õÒ»)TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay + MonthAdd(curMonth - 1) - 38If ((curYear Mod 4) = 0 And curMonth > 2) ThenTheDate = TheDate + 1End If'¼ÆËãÅ©ÀúÌì¸É¡¢µØÖ§¡¢Ô¡¢ÈÕisEnd = 0m = 0DoIf (NongliData(m) < 4095) Thenk = 11Elsek = 12End Ifn = kDoIf (n < 0) ThenExit DoEnd If'»ñÈ¡NongliData(m)µÄµÚn¸ö¶þ½øÖÆλµÄÖµbit = NongliData(m)For i = 1 To n Step 1bit = Int(bit / 2)Nextbit = bit Mod 2If (TheDate <= 29 + bit) ThenisEnd = 1Exit DoEnd IfTheDate = TheDate - 29 - bitn = n - 1LoopIf (isEnd = 1) ThenExit DoEnd Ifm = m + 1LoopcurYear = 1921 + mcurMonth = k - n + 1curDay = TheDateIf (k = 12) ThenIf (curMonth = (Int(NongliData(m) / 65536) + 1)) ThencurMonth = 1 - curMonthElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) ThencurMonth = curMonth - 1End IfEnd If'Éú³ÉÅ©ÀúÌì¸É¡¢µØÖ§¡¢ÊôÏà ==> NongliStrNongliStr = "Å©Àú" & TianGan(((curYear - 4) Mod 60) Mod 10) & DiZhi(((curYear - 4) Mod 60) Mod 12) & "Äê"NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"'Éú³ÉÅ©ÀúÔ¡¢ÈÕ ==> NongliDayStrIf (curMonth < 1) ThenNongliDayStr = "Èò" & MonName(-1 * curMonth)ElseNongliDayStr = MonName(curMonth)End IfNongliDayStr = NongliDayStr & "ÔÂ"NongliDayStr = NongliDayStr & DayName(curDay)NongLi = NongliStr & NongliDayStrEnd Function。

wps转农历函数

wps转农历函数

wps转农历函数
在WPS表格中,将公历日期转换为农历日期可以使用以下函数:
1. 首先,选中要填写农历日期的单元格。

2. 然后,在选中的单元格中输入以下函数:
```
=MID("甲乙丙丁戊己庚辛壬癸", MOD(TEXT(A2, "[-130000]e")-4, 10)1, 1)&MID("子丑寅卯辰巳午未申酉戌亥", MOD(TEXT(A2, "[-130000]e")-4, 12)1, 1)&"年"&TEXT(A2, "[-130000][DBNum1]m月d日")
```
其中,A2为要转换的公历日期所在的单元格。

3. 输入函数后,按回车键确认。

此时,该单元格中会显示对应的农历日期。

4. 如果需要批量转换其他公历日期,只需将上述函数复制到其他需要转换的单元格即可。

请注意,此方法仅适用于WPS表格,并且要求单元格格式设置为“常
规”。

在Excel中,可以使用类似的函数进行公历到农历的转换。

excel公历转农历的四种方法

excel公历转农历的四种方法

excel公历转农历的四种方法excel公历转农历方法一:使用text函数A列是公历日期,我们在B1单元格输入公式:=TEXT(A1,"[$-130000]yyyy年m月"&I F(LEN(--TEXT(A1,"[$-130000]dd"))=1,"初","")&"d"),下拉完成公历转农历。

excel公历转农历方法二:使用text+MID函数A列仍然是公历,B1输入公式:=MID("甲乙丙丁戊己庚辛壬癸",MOD(TEXT(A1,"[$-13 0000]e")-4,10)+1,1)&MID("子丑寅卯辰巳午未申酉戌亥",MOD(TEXT(A1,"[$-130000]e")-4, 12)+1,1)&"年"&TEXT(A1,"[$-130000][DBNum1]m月d日"即可。

excel公历转农历方法三:使用text+MID+ CHOOSE+ YEAR函数A1为公历,B1输入:=CHOOSE(MOD(YEAR(A1)-1900,10)+1,"庚","辛","壬","癸","甲", "乙","丙","丁","戊","己")&CHOOSE(MOD(YEAR(A1)-1900,12)+1,"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥")&TEXT(A1,"[dbnum1][$-130000]年m月"&IF(--TEXT(A1, "[$-130000]d")<11,"初","")&TEXT(A1,"[dbnum1][$-130000]d"))excel公历转农历方法四:使用自定义函数上面介绍的excel公历转农历都是使用excel内置函数完成的,有一个弊端就是公式太长,如果使用自定义函数,在公式栏就可以简化输入。

excel公历转农历的方法

excel公历转农历的方法

excel公历转农历的方法
在 Excel 中实现公历转农历的步骤如下:
1. 在 Excel 中选择“数据”选项卡,然后选择“自定义日期公式”。

2. 在“自定义日期公式”对话框中,选择“输入函数”选项卡,然后选择“整除”函数。

3. 在“输入函数”对话框中,输入“=MOD(公历日期, 12)”,然后将鼠标指针移动到该公式上,按下左键,直到公式被填充完整。

4. 在“自定义日期公式”对话框中选择“输出函数”选项卡,然后选择“整除”函数。

5. 在“输出函数”对话框中,输入“=MOD(农历日期, 12)”,然后将鼠标指针移动到该公式上,按下左键,直到公式被填充完整。

这样,Excel 中输入的公历日期就可以转换为农历日期了。

注意,农历日期需要闰年或平年对应的月份进行调整,如 2 月有 29 天,就需要加上 1 个月。

Excel中阳历转阴历的处理技巧-日历模板(2)

Excel中阳历转阴历的处理技巧-日历模板(2)

Excel中阳历转阴历的处理技巧-日历模板(2)使用Excel函数制作一个2023年日历(1)今天我们介绍日历制作中的日程及阴历处理。

日程及节假日安排先来看日程以及节假日安排。

上图是日程数据以及节假日和调休的数据,都记录在超级表中。

剩下的事情就是在日历当中进行展示在全年的日历当中展示很容易,只要用条件格式,将对应日期在表中用VLOOKUP函数检查,只要找到了活动这一列不为空,不返回错误值,那么就表示它有一个日程,就可以给单元格变色。

节假日也是如此,在节假日表中查找相应的日期,返回第二列,如果不返回错误值并且不返回空白单元格,就表该天是节假日,需要变色。

周末上班也是同样的方法。

在单月日历中显示需要用另外的逻辑,我们后面介绍。

阴历处理Excel提供了一种很简单的方式:自定义格式,来帮助我们将阳历转为阴历。

所以,我们可以通过TEXT函数来实现转换:•••lunar_day, TEXT(theday, "[$-130000]d"),lunar_month, TEXT(theday, "[$-13000]m"),lunar_year, TEXT(theday, "[$-13000]yyyy") 我们将一个标准日期转换为阴历的日,月,年。

但是工作并没有完成,因为这么转换后有几个问题:1.日期处理:转换后的日是1,2,3,4,....,但是日历中需要显示为大写,比如11,应该显示为十一,这可以通过隐藏函数NUMBERSTRING来实现。

不过还需要进行仔细处理:a.1~10之间的日期应该显示为初一~初十b.11~19转为大写后,显示为一十一等,应该去掉开始的一,显示为十一c.20~29转为大写后,显示为二十一等,但是中文习惯上写作廿一d.每月1号应该显示为月份,而不是初一2.月份处理:转换后的月份为1,2,3,4,5,... 12,13。

大写后是一,二,......,十,一十一,一十二,一十三等。

excel制作周历 农历阳历转换

excel制作周历 农历阳历转换

步骤一,在Excel工作表界面下按<ALT+F11>组合键打开VBA窗口,进入VBA编辑环境,在其窗口的菜单栏上依次单击“插入”→“模块”,可在当前VBA工程中插入模块,并直接进入此模块的代码编辑区域。

可在此编辑区域中输入自定义函数的程序代码,如图:Public Function NongLi(Optional XX_DATE As Date)Dim MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11), ShuXiang(11), DayName(30), MonName(12)Dim curTime, curYear, curMonth, curDayDim GongliStr, NongliStr, NongliDayStrDim i, m, n, k, isEnd, bit, TheDate'获取当前系统时间curTime = XX_DATE'天干名称TianGan(0) = "甲"TianGan(1) = "乙"TianGan(2) = "丙"TianGan(3) = "丁"TianGan(4) = "戊"TianGan(5) = "己"TianGan(6) = "庚"TianGan(7) = "辛"TianGan(8) = "壬"TianGan(9) = "癸"'地支名称DiZhi(0) = "子"DiZhi(1) = "丑"DiZhi(2) = "寅"DiZhi(3) = "卯"DiZhi(4) = "辰"DiZhi(5) = "巳"DiZhi(6) = "午"DiZhi(7) = "未"DiZhi(8) = "申"DiZhi(9) = "酉"DiZhi(10) = "戌"DiZhi(11) = "亥"'属相名称ShuXiang(0) = "鼠" ShuXiang(1) = "牛" ShuXiang(2) = "虎" ShuXiang(3) = "兔" ShuXiang(4) = "龙" ShuXiang(5) = "蛇" ShuXiang(6) = "马" ShuXiang(7) = "羊" ShuXiang(8) = "猴" ShuXiang(9) = "鸡" ShuXiang(10) = "狗" ShuXiang(11) = "猪" '农历日期名DayName(0) = "*" DayName(1) = "初一" DayName(2) = "初二" DayName(3) = "初三" DayName(4) = "初四" DayName(5) = "初五" DayName(6) = "初六" DayName(7) = "初七" DayName(8) = "初八" DayName(9) = "初九" DayName(10) = "初十" DayName(11) = "十一" DayName(12) = "十二" DayName(13) = "十三" DayName(14) = "十四" DayName(15) = "十五" DayName(16) = "十六"DayName(17) = "十七" DayName(18) = "十八" DayName(19) = "十九" DayName(20) = "二十" DayName(21) = "廿一" DayName(22) = "廿二" DayName(23) = "廿三" DayName(24) = "廿四" DayName(25) = "廿五" DayName(26) = "廿六" DayName(27) = "廿七" DayName(28) = "廿八" DayName(29) = "廿九" DayName(30) = "三十" '农历月份名MonName(0) = "*" MonName(1) = "正" MonName(2) = "二" MonName(3) = "三" MonName(4) = "四" MonName(5) = "五" MonName(6) = "六" MonName(7) = "七" MonName(8) = "八" MonName(9) = "九" MonName(10) = "十" MonName(11) = "十一" MonName(12) = "腊"'公历每月前面的天数MonthAdd(0) = 0 MonthAdd(1) = 31 MonthAdd(2) = 59 MonthAdd(3) = 90 MonthAdd(4) = 120 MonthAdd(5) = 151 MonthAdd(6) = 181 MonthAdd(7) = 212 MonthAdd(8) = 243 MonthAdd(9) = 273 MonthAdd(10) = 304 MonthAdd(11) = 334'农历数据NongliData(0) = 2635 NongliData(1) = 333387NongliData(3) = 1748 NongliData(4) = 267701 NongliData(5) = 694 NongliData(6) = 2391 NongliData(7) = 133423 NongliData(8) = 1175 NongliData(9) = 396438 NongliData(10) = 3402 NongliData(11) = 3749 NongliData(12) = 331177 NongliData(13) = 1453 NongliData(14) = 694 NongliData(15) = 201326 NongliData(16) = 2350 NongliData(17) = 465197 NongliData(18) = 3221 NongliData(19) = 3402 NongliData(20) = 400202 NongliData(21) = 2901 NongliData(22) = 1386 NongliData(23) = 267611 NongliData(24) = 605 NongliData(25) = 2349 NongliData(26) = 137515 NongliData(27) = 2709 NongliData(28) = 464533 NongliData(29) = 1738 NongliData(30) = 2901 NongliData(31) = 330421 NongliData(32) = 1242 NongliData(33) = 2651 NongliData(34) = 199255 NongliData(35) = 1323 NongliData(36) = 529706 NongliData(37) = 3733 NongliData(38) = 1706 NongliData(39) = 398762 NongliData(40) = 2741 NongliData(41) = 1206 NongliData(42) = 267438 NongliData(43) = 2647 NongliData(44) = 1318 NongliData(45) = 204070NongliData(47) = 461653 NongliData(48) = 1386 NongliData(49) = 2413 NongliData(50) = 330077 NongliData(51) = 1197 NongliData(52) = 2637 NongliData(53) = 268877 NongliData(54) = 3365 NongliData(55) = 531109 NongliData(56) = 2900 NongliData(57) = 2922 NongliData(58) = 398042 NongliData(59) = 2395 NongliData(60) = 1179 NongliData(61) = 267415 NongliData(62) = 2635 NongliData(63) = 661067 NongliData(64) = 1701 NongliData(65) = 1748 NongliData(66) = 398772 NongliData(67) = 2742 NongliData(68) = 2391 NongliData(69) = 330031 NongliData(70) = 1175 NongliData(71) = 1611 NongliData(72) = 200010 NongliData(73) = 3749 NongliData(74) = 527717 NongliData(75) = 1452 NongliData(76) = 2742 NongliData(77) = 332397 NongliData(78) = 2350 NongliData(79) = 3222 NongliData(80) = 268949 NongliData(81) = 3402 NongliData(82) = 3493 NongliData(83) = 133973 NongliData(84) = 1386 NongliData(85) = 464219 NongliData(86) = 605 NongliData(87) = 2349 NongliData(88) = 334123 NongliData(89) = 2709NongliData(91) = 267946NongliData(92) = 2773NongliData(93) = 592565NongliData(94) = 1210NongliData(95) = 2651NongliData(96) = 395863NongliData(97) = 1323NongliData(98) = 2707NongliData(99) = 265877'生成当前公历年、月、日==> GongliStrcurYear = Year(curTime)curMonth = Month(curTime)curDay = Day(curTime)GongliStr = curYear & "年"If (curMonth < 10) ThenGongliStr = GongliStr & "0" & curMonth & "月"ElseGongliStr = GongliStr & curMonth & "月"End IfIf (curDay < 10) ThenGongliStr = GongliStr & "0" & curDay & "日"ElseGongliStr = GongliStr & curDay & "日"End If'计算到初始时间1921年2月8日的天数:1921-2-8(正月初一)TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay + MonthAdd(curMonth - 1) - 38If ((curYear Mod 4) = 0 And curMonth > 2) ThenTheDate = TheDate + 1End If'计算农历天干、地支、月、日isEnd = 0m = 0DoIf (NongliData(m) < 4095) Thenk = 11Elsek = 12End Ifn = kDoIf (n < 0) ThenExit DoEnd If'获取NongliData(m)的第n个二进制位的值bit = NongliData(m)For i = 1 To n Step 1bit = Int(bit / 2)Nextbit = bit Mod 2If (TheDate <= 29 + bit) ThenisEnd = 1Exit DoEnd IfTheDate = TheDate - 29 - bitn = n - 1LoopIf (isEnd = 1) ThenExit DoEnd Ifm = m + 1LoopcurYear = 1921 + mcurMonth = k - n + 1curDay = TheDateIf (k = 12) ThenIf (curMonth = (Int(NongliData(m) / 65536) + 1)) ThencurMonth = 1 - curMonthElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) ThencurMonth = curMonth - 1End IfEnd If'生成农历天干、地支、属相==> NongliStrNongliStr = "农历" & TianGan(((curYear - 4) Mod 60) Mod 10) & DiZhi(((curYear - 4) Mod 60) Mod 12) & "年"NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"'生成农历月、日==> NongliDayStrIf (curMonth < 1) ThenNongliDayStr = "闰" & MonName(-1 * curMonth)ElseNongliDayStr = MonName(curMonth)End IfNongliDayStr = NongliDayStr & "月"NongliDayStr = NongliDayStr & DayName(curDay)NongLi = NongliStr & NongliDayStrEnd Function步骤2,单击窗口右上角的“关闭”按钮关闭VBA编辑窗口,返回到工作表窗口中。

如何使用Excel公式自动生成日历

如何使用Excel公式自动生成日历

如何使用Excel公式自动生成日历Excel作为一款功能强大的电子表格软件,不仅可以处理数据,绘制图表,还可以用来自动生成日历。

在处理时间相关的任务时,使用Excel公式生成日历可以提高工作效率和准确性。

本文将介绍如何使用Excel公式来自动生成日历,并给出具体的步骤和示例。

一、创建基本表格首先,在Excel中创建一个基本的日历表格。

选择一个空白的单元格作为表格的起始位置,然后设置表格的列宽和行高,以适应日历的展示需求。

可以根据实际情况调整列宽和行高的大小。

二、填写日期数据在第一行填写日历的月份和年份信息,比如“2022年1月”。

从第二行开始填写日期数据,按照日历的布局依次填写每一天的日期。

可以使用Excel的自动填充功能,比如选择第一个日期单元格,然后将鼠标移动到右下角的小方块,双击鼠标左键即可自动填充整个日期序列。

三、使用公式生成日期Excel提供了一些内置的日期函数,可以用来生成和处理日期数据。

使用公式前需要了解一些常用的日期函数,如“YEAR”函数用于提取年份,“MONTH”函数用于提取月份,“DAY”函数用于提取日期等。

以生成2022年1月的日历为例,我们将在第二行开始填写日期数据。

在第二行第二列的单元格中输入公式“=DATE(2022,1,1)”来生成1月1日的日期,在第二行第三列的单元格中输入公式“=DATE(2022,1,2)”来生成1月2日的日期,以此类推。

然后可以使用自动填充功能将公式应用到整个日期序列中。

四、设置日期格式在生成日期后,Excel默认将日期显示为数字格式。

为了更好地呈现日历的效果,我们需要对日期进行格式设置。

选中日期单元格区域,右键点击,选择“格式单元格”选项,然后在弹出的对话框中选择“日期”选项,在下方的“类型”列表中选择合适的日期格式,如“年-月-日”、“月/日”等。

点击“确定”完成格式设置。

五、添加其他信息除了日期外,我们还可以在日历表格中添加其他的信息,如星期几、节假日等。

excel计算农历的if函数公式

excel计算农历的if函数公式

excel计算农历的if函数公式Excel的IF函数是一种非常常用的计算函数,通过IF函数可以进行条件判断,以此来选择不同的计算方式。

今天,我们将介绍如何利用IF函数计算农历。

首先,我们需要掌握一些农历的基本知识。

农历是一种以月亮运行周期来计算时间的历法,每个月份有一个月份名,每个月份又以十二生肖来称呼。

而农历年的开始时间通常在公历的1月底或2月初,这取决于每年春节的日期。

在Excel中计算农历,我们需要先了解两个关键的数值:一是每个农历月(大小月)的天数,二是每个农历年第一个月的开始日。

首先让我们来计算每个农历月的天数,我们可以使用IF函数进行条件判断。

假设我们要计算1920年的农历,我们可以将1月1日设置为农历正月初一,然后我们可以利用IF函数判断每个公历月的天数,如果这个月是农历的大月,则返回30天,如果是小月,则返回29天。

公式如下:=IF(DAY(EOMONTH($A$1,0))>=31,IF(DAY(EOMONTH($A$1,0)-30)>=26,30,29),IF(DAY(EOMONTH($A$1,0))>=26,30,29))其中:$A$1表示我们要计算的年份;EOMONTH函数表示求出对应月份的最后一天。

接下来,让我们来计算每个农历年第一个月的开始日。

由于农历新年通常是在公历1月底或2月初,我们可以通过IF函数判断公历的年份是否和农历的年份相同,并且判断春节是在公历上是否跨越了两个月。

公式如下:=IF(YEAR($A$1)=1920,IF(MONTH($A$1)<=2,0,12),IF(YEAR($A$1)=1921,IF(MONTH($A$1)<=1,0,12),IF(YEAR($A$1)=1922,IF(MONTH($A $1)<=2,0,12))))其中:$A$1表示我们要计算的年份。

以上公式将1920年到1922年的农历年第一个月的开始日都计算了出来,我们可以用其他公历年代替即可。

在Excel中自定义公历转换农历函数2

在Excel中自定义公历转换农历函数2
求阳历2006-11-1日对应的阴历 求阴历2006年正月初一对应的阳历 阳历1975年5月6日出生,今年阴历生日时对应的阳历日期
#NAME? #NAME? #NAME?
阳历生日:阳历1975年5月6日出生,今年阳历生日时对应的阳历日期
#NAME?
End Type
Do
Loop
Loop
&HB4A43, &H4B5537 , &HAD54A, &H955ABF , &H4BA53, &HA5B48, &H652BBC , &H52B50, &HA9345, &H474AB9 ,_
&H6AA4C, &HAD541, &H24DAB6 , &H4B64A, &H69573D , &HA4E51, &HD2646, &H5E933A , &HD534D, &H5AA43, _
LunarDat a.leapmo nth = Int(ng / d)
ng = ng Mod d
d= &H80
mdata = Int(ng / d)
ng = ng Mod d
d= &H20
LunarDat a.sp_mon th = Int(ng / d)
LunarDat a.sp_day = ng Mod d
y= a.Month( 13)
Else
l_month = l_month +1
y= a.Month( l_month)
End If Loop
l_day = l_day + 1
lunar = l_year & "-" & l_month & "-" & l_day

自己动手制作Excel万年历

自己动手制作Excel万年历

自己动手制作Excel万年历自己动手制作Excel万年历在网上看到别人用Excel制作的万年历非常精美,于是自己动手,跟着学习,自己制作一了属于自己的“万年历”;现在把制作过程和大家一起分享!首先还是看看我制作的“万年历”的最终效果:这个万年历可以显示当月的月历,还可以随意查阅任何日期所属的月历,非常方便,一起来试试吧!第一步:启动Excel2003,新建一个工作表,取名保存(如万年历.xls);并在相应的单元格中输入如图①所示的内容。

其中:在I1、I2单元格分别输入1900、1901,然后同时选中I1、I2单元格,用“填充柄”向下拖拉至I151单元格,即输入1900―2050年份序列;同样的方法,在J1至J12单元格中输入1―12月份序列。

第二步:同时选中B1、C1、D1单元格,单击“格式”工具栏上的“合并及居中”按钮,将其合并成一个单元格,并输入公式=TODAY()后回车;再次选中B1(合并后的)单元格,执行“格式→单元格→数字→分类→日期”,在右侧“类型”下面选中“二○○一年三月十四日”选项,“确定”退出,将日期设置成中文形式。

(如图②)注:TODAY()函数用于提取当前系统日期,请将系统日期一定要调整准确哟。

第三步:选中F1单元格,输入公式=IF(WEEKDAY(B1,2)=7,"日",WEEKDAY(B1,2))后回车;再次选中F1单元格,执行“格式→单元格→数字→分类→特殊”,在右侧“类型”下面选中“中文小写数字”选项,“确定”退出,将“星期数”设置成中文小写形式。

(如图③)注:上述公式的含义是:如果(IF)当前日期(B1)是星期“7”(WEEKDAY(B1,2)=7),则在F1单元格中显示“日”,否则,直接显示出星期的数值(WEEKDAY(B1,2))。

第四步:选中H1单元格,输入公式=NOW()后回车;再次选中H1单元格,执行“格式→单元格→数字→分类→时间”,在右侧“类型”下面选中一款时间格式,“确定”退出。

在excel中实现阳历转化阴历

在excel中实现阳历转化阴历

步骤一,在Excel工作表界面下按<ALT+F11>组合键打开VBA窗口,进入VBA编辑环境,在其窗口的菜单栏上依次单击“插入”→“模块”,可在当前VBA工程中插入模块,并直接进入此模块的代码编辑区域。

可在此编辑区域中输入自定义函数的程序代码,如图:Public Function NongLi(Optional XX_DATE As Date)Dim MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11), ShuXiang(11), DayName(30), MonName(12)Dim curTime, curYear, curMonth, curDayDim GongliStr, NongliStr, NongliDayStrDim i, m, n, k, isEnd, bit, TheDate'获取当前系统时间curTime = XX_DATE'天干名称TianGan(0) = "甲"TianGan(1) = "乙"TianGan(2) = "丙"TianGan(3) = "丁"TianGan(4) = "戊"TianGan(5) = "己"TianGan(6) = "庚"TianGan(7) = "辛"TianGan(8) = "壬"TianGan(9) = "癸"'地支名称DiZhi(0) = "子"DiZhi(1) = "丑"DiZhi(2) = "寅"DiZhi(3) = "卯"DiZhi(4) = "辰"DiZhi(5) = "巳"DiZhi(6) = "午"DiZhi(7) = "未"DiZhi(8) = "申"DiZhi(9) = "酉"DiZhi(10) = "戌"DiZhi(11) = "亥"'属相名称ShuXiang(0) = "鼠" ShuXiang(1) = "牛" ShuXiang(2) = "虎" ShuXiang(3) = "兔" ShuXiang(4) = "龙" ShuXiang(5) = "蛇" ShuXiang(6) = "马" ShuXiang(7) = "羊" ShuXiang(8) = "猴" ShuXiang(9) = "鸡" ShuXiang(10) = "狗" ShuXiang(11) = "猪" '农历日期名DayName(0) = "*" DayName(1) = "初一" DayName(2) = "初二" DayName(3) = "初三" DayName(4) = "初四" DayName(5) = "初五" DayName(6) = "初六" DayName(7) = "初七" DayName(8) = "初八" DayName(9) = "初九" DayName(10) = "初十" DayName(11) = "十一" DayName(12) = "十二" DayName(13) = "十三" DayName(14) = "十四" DayName(15) = "十五" DayName(16) = "十六" DayName(17) = "十七" DayName(18) = "十八" DayName(19) = "十九" DayName(20) = "二十" DayName(21) = "廿一" DayName(22) = "廿二" DayName(23) = "廿三" DayName(24) = "廿四" DayName(25) = "廿五" DayName(26) = "廿六" DayName(27) = "廿七" DayName(28) = "廿八" DayName(29) = "廿九" DayName(30) = "三十"'农历月份名MonName(0) = "*" MonName(1) = "正" MonName(2) = "二" MonName(3) = "三" MonName(4) = "四" MonName(5) = "五" MonName(6) = "六" MonName(7) = "七" MonName(8) = "八" MonName(9) = "九" MonName(10) = "十" MonName(11) = "十一" MonName(12) = "腊"'公历每月前面的天数MonthAdd(0) = 0 MonthAdd(1) = 31 MonthAdd(2) = 59 MonthAdd(3) = 90 MonthAdd(4) = 120 MonthAdd(5) = 151 MonthAdd(6) = 181 MonthAdd(7) = 212 MonthAdd(8) = 243 MonthAdd(9) = 273 MonthAdd(10) = 304 MonthAdd(11) = 334'农历数据NongliData(0) = 2635 NongliData(1) = 333387 NongliData(2) = 1701 NongliData(3) = 1748 NongliData(4) = 267701 NongliData(5) = 694 NongliData(6) = 2391 NongliData(7) = 133423 NongliData(8) = 1175 NongliData(9) = 396438 NongliData(10) = 3402 NongliData(11) = 3749 NongliData(12) = 331177 NongliData(13) = 1453 NongliData(14) = 694 NongliData(15) = 201326NongliData(17) = 465197 NongliData(18) = 3221 NongliData(19) = 3402 NongliData(20) = 400202 NongliData(21) = 2901 NongliData(22) = 1386 NongliData(23) = 267611 NongliData(24) = 605 NongliData(25) = 2349 NongliData(26) = 137515 NongliData(27) = 2709 NongliData(28) = 464533 NongliData(29) = 1738 NongliData(30) = 2901 NongliData(31) = 330421 NongliData(32) = 1242 NongliData(33) = 2651 NongliData(34) = 199255 NongliData(35) = 1323 NongliData(36) = 529706 NongliData(37) = 3733 NongliData(38) = 1706 NongliData(39) = 398762 NongliData(40) = 2741 NongliData(41) = 1206 NongliData(42) = 267438 NongliData(43) = 2647 NongliData(44) = 1318 NongliData(45) = 204070 NongliData(46) = 3477 NongliData(47) = 461653 NongliData(48) = 1386 NongliData(49) = 2413 NongliData(50) = 330077 NongliData(51) = 1197 NongliData(52) = 2637 NongliData(53) = 268877 NongliData(54) = 3365 NongliData(55) = 531109 NongliData(56) = 2900 NongliData(57) = 2922 NongliData(58) = 398042 NongliData(59) = 2395NongliData(61) = 267415NongliData(62) = 2635NongliData(63) = 661067NongliData(64) = 1701NongliData(65) = 1748NongliData(66) = 398772NongliData(67) = 2742NongliData(68) = 2391NongliData(69) = 330031NongliData(70) = 1175NongliData(71) = 1611NongliData(72) = 200010NongliData(73) = 3749NongliData(74) = 527717NongliData(75) = 1452NongliData(76) = 2742NongliData(77) = 332397NongliData(78) = 2350NongliData(79) = 3222NongliData(80) = 268949NongliData(81) = 3402NongliData(82) = 3493NongliData(83) = 133973NongliData(84) = 1386NongliData(85) = 464219NongliData(86) = 605NongliData(87) = 2349NongliData(88) = 334123NongliData(89) = 2709NongliData(90) = 2890NongliData(91) = 267946NongliData(92) = 2773NongliData(93) = 592565NongliData(94) = 1210NongliData(95) = 2651NongliData(96) = 395863NongliData(97) = 1323NongliData(98) = 2707NongliData(99) = 265877'生成当前公历年、月、日==> GongliStr curYear = Year(curTime)curMonth = Month(curTime)curDay = Day(curTime)GongliStr = curYear & "年"If (curMonth < 10) ThenGongliStr = GongliStr & "0" & curMonth & "月"ElseGongliStr = GongliStr & curMonth & "月"End IfIf (curDay < 10) ThenGongliStr = GongliStr & "0" & curDay & "日"ElseGongliStr = GongliStr & curDay & "日"End If'计算到初始时间1921年2月8日的天数:1921-2-8(正月初一)TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay + MonthAdd(curMonth - 1) - 38If ((curYear Mod 4) = 0 And curMonth > 2) ThenTheDate = TheDate + 1End If'计算农历天干、地支、月、日isEnd = 0m = 0DoIf (NongliData(m) < 4095) Thenk = 11Elsek = 12End Ifn = kDoIf (n < 0) ThenExit DoEnd If'获取NongliData(m)的第n个二进制位的值bit = NongliData(m)For i = 1 To n Step 1bit = Int(bit / 2)Nextbit = bit Mod 2If (TheDate <= 29 + bit) ThenisEnd = 1Exit DoEnd IfTheDate = TheDate - 29 - bitn = n - 1LoopIf (isEnd = 1) ThenExit DoEnd Ifm = m + 1LoopcurYear = 1921 + mcurMonth = k - n + 1curDay = TheDateIf (k = 12) ThenIf (curMonth = (Int(NongliData(m) / 65536) + 1)) ThencurMonth = 1 - curMonthElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) ThencurMonth = curMonth - 1End IfEnd If'生成农历天干、地支、属相==> NongliStrNongliStr = "农历" & TianGan(((curYear - 4) Mod 60) Mod 10) & DiZhi(((curYear - 4) Mod 60) Mod 12) & "年"NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"'生成农历月、日==> NongliDayStrIf (curMonth < 1) ThenNongliDayStr = "闰" & MonName(-1 * curMonth)ElseNongliDayStr = MonName(curMonth)End IfNongliDayStr = NongliDayStr & "月"NongliDayStr = NongliDayStr & DayName(curDay)NongLi = NongliStr & NongliDayStrEnd Function步骤2,单击窗口右上角的“关闭”按钮关闭VBA编辑窗口,返回到工作表窗口中。

Excel的公历与农历转换

Excel的公历与农历转换
/Article/ShowArticle.asp?ArticleID=249(第 1/7 页)2005-11-7 22:20:36
公历与农历的转换
DiZhi(8) = "申" DiZhi(9) = "酉" DiZhi(10) = "戌" DiZhi(11) = "亥" '属相名称 ShuXiang(0) = "鼠" ShuXiang(1) = "牛" ShuXiang(2) = "虎" ShuXiang(3) = "兔" ShuXiang(4) = "龙" ShuXiang(5) = "蛇" ShuXiang(6) = "马" ShuXiang(7) = "羊" ShuXiang(8) = "猴" ShuXiang(9) = "鸡" ShuXiang(10) = "狗" ShuXiang(11) = "猪" '农历日期名 DayName(0) = "*" DayName(1) = "初一" DayName(2) = "初二" DayName(3) = "初三" DayName(4) = "初四" DayName(5) = "初五" DayName(6) = "初六" DayName(7) = "初七" DayName(8) = "初八" DayName(9) = "初九" DayName(10) = "初十" DayName(11) = "十一" DayName(12) = "十二" DayName(13) = "十三" DayName(14) = "十四" DayName(15) = "十五" DayName(16) = "十六" DayName(17) = "十七" DayName(18) = "十八" DayName(19) = "十九" DayName(20) = "二十" DayName(21) = "廿一" DayName(22) = "廿二" DayName(23) = "廿三" DayName(24) = "廿四" DayName(25) = "廿五" DayName(26) = "廿六" DayName(27) = "廿七" DayName(28) = "廿八" DayName(29) = "廿九" DayName(30) = "三十" '农历月份名 MonName(0) = "*" MonName(1) = "正" MonName(2) = "二" MonName(3) = "三" MonName(4) = "四" MonName(5) = "五" MonName(6) = "六"

excel公历转农历的四种方法

excel公历转农历的四种方法

excel公历转农历的四种方法excel公历转农历方法一:使用text函数A列是公历日期,我们在B1单元格输入公式:=TEXT(A1,"[$-130000]yyyy年m月"&I F(LEN(--TEXT(A1,"[$-130000]dd"))=1,"初","")&"d"),下拉完成公历转农历。

excel公历转农历方法二:使用text+MID函数A列仍然是公历,B1输入公式:=MID("甲乙丙丁戊己庚辛壬癸",MOD(TEXT(A1,"[$-13 0000]e")-4,10)+1,1)&MID("子丑寅卯辰巳午未申酉戌亥",MOD(TEXT(A1,"[$-130000]e")-4, 12)+1,1)&"年"&TEXT(A1,"[$-130000][DBNum1]m月d日"即可。

excel公历转农历方法三:使用text+MID+ CHOOSE+ YEAR函数A1为公历,B1输入:=CHOOSE(MOD(YEAR(A1)-1900,10)+1,"庚","辛","壬","癸","甲", "乙","丙","丁","戊","己")&CHOOSE(MOD(YEAR(A1)-1900,12)+1,"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥")&TEXT(A1,"[dbnum1][$-130000]年m月"&IF(--TEXT(A1, "[$-130000]d")<11,"初","")&TEXT(A1,"[dbnum1][$-130000]d"))excel公历转农历方法四:使用自定义函数上面介绍的excel公历转农历都是使用excel内置函数完成的,有一个弊端就是公式太长,如果使用自定义函数,在公式栏就可以简化输入。

Excel做个自动的万年历,这个操作实在是太溜了~

Excel做个自动的万年历,这个操作实在是太溜了~

Excel做个⾃动的万年历,这个操作实在是太溜了~万年历。

是⽣活中⽐较常见的⼀个东西,在Excel中也能做出来同样的效果。

本期要点:条件格式,⽇期函数,控件,⾃定义格式。

具体效果如下图所⽰:对于上⾯的万年历,许多⼩伙伴们都问了,那怎么样才能做出这样的⼀个万年历呢,这个万年历是练习Excel的最好的素材,可以综合地练习函数,条件格式,控件、⾃定义格式等的协同应⽤。

下⾯⽼师和⼤家⼀起来学习万年历的制作。

01制作⽇历的框架在⼀个空⽩的⼯作表中制作⼀个空⽩的表格,做好颜⾊的美化。

如下图所⽰:02 01添加控件操作步骤:在相应的位置单击【开发⼯具】-【插⼊】,选择【数值调节钮】,然后拖放⿏标在相应的位置插⼊,然后右键单击【设置控件格式】,在打开的对话框中的【当前值】输⼊“2019”,【最⼩值】为1900,【最⼤值】为9999,【步长】为1,【单元格链接】为B1;同样地设置⽉份的调节按钮。

如下图所⽰:03 01VLOOKUP函数在B4单元格中输⼊公式:=IF(MONTH(DATE($B$1,$D$1,1)-WEEKDAY(DATE($B$1,$D$1,1),2) COLUMN(A:A)-1 ROW(1:1)*7-7)=$D$1,DATE($B$1,$D$1,1)-WEEKDAY(DATE($B$1,$D$1,1),2) COLUMN(A:A)-1 ROW(1:1)*7-7,'')按Enter键完成后下向下填充⾄整个⽇历表。

效果如下:选中区域B4:H9单元格,然后将单元格格式⾃定义为:dd。

如下图所⽰:选中区域B4:H9单元格,然后将单元格格式⾃定义为:dd。

如下图所⽰:05 01设置条件格式为了突出显⽰当前⽇期的单元格,所以要⾼亮显⽰,效果与具体操作如下:。

公历与农历自动转化表格

公历与农历自动转化表格

公历与农历自动转化表格公历与农历的转换涉及到农历的闰月和年份的差异,因此需要使用一些特殊的计算方法。

以下是一个简单的公历与农历自动转化的表格,你可以在Excel等表格软件中使用:
在这个表格中,"公历日期"列是公历日期,"农历日期"列是对应的农历日期。

请注意,这只是一个简化的示例,实际上,要实现精确的公历与农历转化可能需要使用专业的农历计算库或算法。

如果你需要实现更复杂的公历与农历转化功能,建议使用专业的日期计算库或在线工具,这样可以确保准确性和可靠性。

1/ 1。

excel制作周历农历阳历转换

excel制作周历农历阳历转换

excel制作周历农历阳历转换步骤一,在Excel工作表界面下按组合键打开VBA窗口,进入VBA编辑环境,在其窗口的菜单栏上依次单击“插入”→“模块”,可在当前VBA工程中插入模块,并直接进入此模块的代码编辑区域。

可在此编辑区域中输入自定义函数的程序代码,如图:Public Function NongLi(Optional XX_DATE As Date)Dim MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11), ShuXiang(11), DayName(30), MonName(12)Dim curTime, curYear, curMonth, curDayDim GongliStr, NongliStr, NongliDayStrDim i, m, n, k, isEnd, bit, TheDate'获取当前系统时间curTime = XX_DATE'天干名称TianGan(0) = "甲"TianGan(1) = "乙"TianGan(2) = "丙"TianGan(3) = "丁"TianGan(4) = "戊"TianGan(5) = "己"TianGan(6) = "庚"TianGan(7) = "辛"TianGan(8) = "壬"TianGan(9) = "癸"'地支名称DiZhi(0) = "子"DiZhi(1) = "丑"DiZhi(2) = "寅"DiZhi(3) = "卯"DiZhi(4) = "辰"DiZhi(5) = "巳"DiZhi(6) = "午"DiZhi(7) = "未"DiZhi(8) = "申"DiZhi(9) = "酉"DiZhi(10) = "戌"DiZhi(11) = "亥"'属相名称ShuXiang(0) = "鼠" ShuXiang(1) = "牛" ShuXiang(2) = "虎" ShuXiang(3) = "兔" ShuXiang(4) = "龙" ShuXiang(5) = "蛇" ShuXiang(6) = "马" ShuXiang(7) = "羊" ShuXiang(8) = "猴" ShuXiang(9) = "鸡" ShuXiang(10) = "狗" ShuXiang(11) = "猪" '农历日期名DayName(0) = "*" DayName(1) = "初一" DayName(2) = "初二" DayName(3) = "初三" DayName(4) = "初四" DayName(5) = "初五" DayName(6) = "初六" DayName(7) = "初七" DayName(8) = "初八" DayName(9) = "初九" DayName(10) = "初十" DayName(11) = "十一" DayName(12) = "十二" DayName(13) = "十三" DayName(14) = "十四" DayName(15) = "十五" DayName(16) = "十六"DayName(17) = "十七" DayName(18) = "十八" DayName(19) = "十九" DayName(20) = "二十" DayName(21) = "廿一"DayName(22) = "廿二" DayName(23) = "廿三" DayName(24) = "廿四" DayName(25) = "廿五" DayName(26) = "廿六" DayName(27) = "廿七" DayName(28) = "廿八" DayName(29) = "廿九" DayName(30) = "三十" '农历月份名MonName(0) = "*" MonName(1) = "正" MonName(2) = "二" MonName(3) = "三" MonName(4) = "四" MonName(5) = "五" MonName(6) = "六" MonName(7) = "七" MonName(8) = "八" MonName(9) = "九" MonName(10) = "十" MonName(11) = "十一" MonName(12) = "腊"'公历每月前面的天数MonthAdd(0) = 0 MonthAdd(1) = 31 MonthAdd(2) = 59 MonthAdd(3) = 90 MonthAdd(4) = 120 MonthAdd(5) = 151 MonthAdd(6) = 181 MonthAdd(7) = 212 MonthAdd(8) = 243 MonthAdd(9) = 273 MonthAdd(10) = 304 MonthAdd(11) = 334'农历数据NongliData(0) = 2635 NongliData(1) = 333387NongliData(3) = 1748 NongliData(4) = 267701 NongliData(5) = 694 NongliData(6) = 2391 NongliData(7) = 133423 NongliData(8) = 1175 NongliData(9) = 396438 NongliData(10) = 3402 NongliData(11) = 3749 NongliData(12) = 331177 NongliData(13) = 1453 NongliData(14) = 694 NongliData(15) = 201326 NongliData(16) = 2350 NongliData(17) = 465197 NongliData(18) = 3221 NongliData(19) = 3402 NongliData(20) = 400202 NongliData(21) = 2901 NongliData(22) = 1386 NongliData(23) = 267611 NongliData(24) = 605 NongliData(25) = 2349 NongliData(26) = 137515 NongliData(27) = 2709 NongliData(28) = 464533 NongliData(29) = 1738 NongliData(30) = 2901 NongliData(31) = 330421 NongliData(32) = 1242 NongliData(33) = 2651 NongliData(34) = 199255 NongliData(35) = 1323 NongliData(36) = 529706 NongliData(37) = 3733NongliData(38) = 1706 NongliData(39) = 398762 NongliData(40) = 2741 NongliData(41) = 1206 NongliData(42) = 267438 NongliData(43) = 2647 NongliData(44) = 1318 NongliData(45) = 204070NongliData(47) = 461653 NongliData(48) = 1386 NongliData(49) = 2413 NongliData(50) = 330077 NongliData(51) = 1197 NongliData(52) = 2637 NongliData(53) = 268877 NongliData(54) = 3365 NongliData(55) = 531109 NongliData(56) = 2900 NongliData(57) = 2922 NongliData(58) = 398042 NongliData(59) = 2395 NongliData(60) = 1179 NongliData(61) = 267415 NongliData(62) = 2635 NongliData(63) = 661067 NongliData(64) = 1701 NongliData(65) = 1748 NongliData(66) = 398772 NongliData(67) = 2742 NongliData(68) = 2391 NongliData(69) = 330031 NongliData(70) = 1175 NongliData(71) = 1611 NongliData(72) = 200010 NongliData(73) = 3749 NongliData(74) = 527717 NongliData(75) = 1452 NongliData(76) = 2742 NongliData(77) = 332397 NongliData(78) = 2350 NongliData(79) = 3222 NongliData(80) = 268949 NongliData(81) = 3402 NongliData(82) = 3493 NongliData(83) = 133973 NongliData(84) = 1386 NongliData(85) = 464219 NongliData(86) = 605 NongliData(87) = 2349 NongliData(88) = 334123 NongliData(89) = 2709NongliData(91) = 267946NongliData(92) = 2773NongliData(93) = 592565NongliData(94) = 1210NongliData(95) = 2651NongliData(96) = 395863NongliData(97) = 1323NongliData(98) = 2707NongliData(99) = 265877'生成当前公历年、月、日==> GongliStrcurYear = Year(curTime)curMonth = Month(curTime)curDay = Day(curTime)GongliStr = curYear & "年"If (curMonth < 10) ThenGongliStr = GongliStr & "0" & curMonth & "月"ElseGongliStr = GongliStr & curMonth & "月"End IfIf (curDay < 10) ThenGongliStr = GongliStr & "0" & curDay & "日"ElseGongliStr = GongliStr & curDay & "日"End If'计算到初始时间1921年2月8日的天数:1921-2-8(正月初一) TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay + MonthAdd(curMonth - 1) - 38If ((curYear Mod 4) = 0 And curMonth > 2) ThenTheDate = TheDate + 1End If'计算农历天干、地支、月、日isEnd = 0m = 0DoIf (NongliData(m) < 4095) Thenk = 11Elsek = 12End Ifn = kDoIf (n < 0) ThenExit DoEnd If'获取NongliData(m)的第n个二进制位的值bit = NongliData(m)For i = 1 To n Step 1bit = Int(bit / 2)Nextbit = bit Mod 2If (TheDate <= 29 + bit) ThenisEnd = 1Exit DoEnd IfTheDate = TheDate - 29 - bitn = n - 1LoopIf (isEnd = 1) ThenExit DoEnd Ifm = m + 1LoopcurYear = 1921 + mcurMonth = k - n + 1curDay = TheDateIf (k = 12) ThenIf (curMonth = (Int(NongliData(m) / 65536) + 1)) Then curMonth = 1 - curMonthElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) ThencurMonth = curMonth - 1End IfEnd If'生成农历天干、地支、属相==> NongliStrNongliStr = "农历" & TianGan(((curYear - 4) Mod 60) Mod 10) & DiZhi(((curYear - 4) Mod 60) Mod 12) & "年"NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"'生成农历月、日==> NongliDayStrIf (curMonth < 1) ThenNongliDayStr = "闰" & MonName(-1 * curMonth)ElseNongliDayStr = MonName(curMonth)End IfNongliDayStr = NongliDayStr & "月"NongliDayStr = NongliDayStr & DayName(curDay)NongLi = NongliStr & NongliDayStrEnd Function步骤2,单击窗口右上角的“关闭”按钮关闭VBA编辑窗口,返回到工作表窗口中。

excell农历和公历转换公式

excell农历和公历转换公式

excell农历和公历转换公式Excel是一款功能强大的电子表格软件,它不仅可以用于数据统计和分析,还可以进行日期转换,包括农历和公历的转换。

在Excel中,我们可以使用一些公式来实现农历和公历的转换。

下面将介绍一些常用的Excel公式,帮助大家在农历和公历之间进行转换。

一、农历转公历公式农历转公历是指将农历日期转换为公历日期。

在Excel中,可以使用以下公式来实现农历转公历的计算:```=DATE(YEAR(公历日期), 2, 1) + 农历天数 - 1```其中,公历日期是指要转换的公历日期,农历天数是指要转换的农历日期对应的天数。

通过这个公式,我们可以将农历日期转换为公历日期。

二、公历转农历公式公历转农历是指将公历日期转换为农历日期。

在Excel中,可以使用以下公式来实现公历转农历的计算:```=公历日期 - DATE(YEAR(公历日期), 2, 1) + 1```其中,公历日期是指要转换的公历日期。

通过这个公式,我们可以将公历日期转换为农历日期。

三、应用示例下面通过一个示例来演示如何在Excel中进行农历和公历的转换。

假设我们要将农历2022年正月初一转换为公历日期。

首先,我们需要知道农历2022年正月初一对应的公历日期是什么。

根据农历日历,我们知道2022年的农历正月初一对应的公历日期是2月1日。

接下来,我们可以使用上述的公式来进行转换。

在一个单元格中输入农历日期2022/1/1,然后在另一个单元格中输入以下公式:```=DATE(YEAR(A1), 2, 1) + A1 - 1```其中,A1是指包含农历日期的单元格。

按下回车键后,我们可以在这个单元格中得到公历日期2022/2/1,这就是农历2022年正月初一对应的公历日期。

类似地,如果我们要将公历日期2022/2/1转换为农历日期,我们可以在一个单元格中输入公历日期2022/2/1,然后在另一个单元格中输入以下公式:```=A1 - DATE(YEAR(A1), 2, 1) + 1```按下回车键后,我们可以在这个单元格中得到农历日期2022/1/1,这就是公历2022/2/1对应的农历日期。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Option Base 1Dim rq As Integer '日期Dim y As Date '农历正月月初一的阳历日期Dim yts As Variant '农历每月的天数Dim yy(2) As Integer '农历闰月数、阳历闰年数(闰年为1,不闰年为0)Dim nl(3, 385) As String '阳历日期字符串、农历日期字符串、农历闰月字符串Function NONGLI(glrq As Date, nlr As Integer)Dim X As Integer, i As Integer, k As Integer, n1 As Integer, n2 As IntegerX = Year(glrq)If X < 1900 Or glrq > #1/28/2101# ThenNONGLI = "?"Exit FunctionEnd If'1、将X年的阴阳历等,通过运行程序2,装入数组If X < 2021 Then Call Array1(X, n1, glrq)If X > 2020 Then Call Array2(X, n1, glrq)'2、查找阳历日期所在数组的序号rqdi2bu: rq = 0If X = 1899 Thenrq = Day(glrq)ElseFor i = 1 To n1If nl(1, i) = glrq Then rq = i: Exit ForNext iEnd If'3、填写"农历日期"(包括节日、纪念日)Dim nongli1$, yr$, yuefen$, yf$, rizi$, rz$Dim jr1 As String, jr2 As String, jr3 As Stringnongli1 = nl(2, rq)'农历日期以"2014-2-1"或"2014-闰9-1"的形式表示yr = Strings.Right(nongli1, Strings.Len(nongli1) - 5) '农历日期以"2-1"或"闰9-1"形式表示yuefen = Strings.Left(yr, Strings.InStrRev(yr, "-") - 1) '农历的月份以"2"或"闰9"形式表示rizi = Strings.Right(yr, Strings.Len(yr) - Strings.InStrRev(yr, "-")) '农历的日子以"2"形式表示Dim yuefenB As Variant, yfB As VariantyuefenB = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, "闰2", "闰3", "闰4", "闰5", "闰6", "闰7", "闰8", "闰9", "闰10", "闰11", "闰12")yfB = Array("正月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "冬月", "腊月", "闰二月", "闰三月", "闰四月", "闰五月", "闰六月", "闰七月", "闰八月", "闰九月", "闰十月", "闰冬月", "闰腊月")For i = 1 To 23'农历的月份以汉字形式表示If yuefen = yuefenB(i) Then yf = yfB(i): Exit ForNext iDim rzB As VariantrzB = Array("初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "廿一", "廿二","廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十")For i = 1 To 30If rizi = i Then rz = rzB(i): Exit For'农历的日子以汉字形式表示Next i'农历节日--jr1If nlr = 3 Then Call nljr(rizi, yuefen, yuefenB, yfB, yr, yts, jr1)'24节气--ji2Dim xiaohan As Datexiaohan = Int(365.242646137797 * Year(glrq) - 693953.924646684)If glrq = xiaohan Then jr2 = "小寒"Dim dahan As Datedahan = Int(365.242629416257 * Year(glrq) - 693939.16865395)If Year(glrq) = 2082 Then dahan = dahan + 1If glrq = dahan Then jr2 = "大寒"Dim lichun As Datelichun = Int(365.24259976737 * Year(glrq) - 693924.346732722)If glrq = lichun Then jr2 = "立春"Dim yushui As Dateyushui = Int(365.242502247697 * Year(glrq) - 693909.331831532)If Year(glrq) = 2059 Or Year(glrq) = 2092 Then yushui = yushui + 1If glrq = yushui Then jr2 = "雨水"Dim jingzhe As Datejingzhe = Int(365.242419549484 * Year(glrq) - 693894.233446856) If Year(glrq) = 2047 Then jingzhe = jingzhe + 1If glrq = jingzhe Then jr2 = "惊蛰"Dim chunfen As Datechunfen = Int(365.242305278251 * Year(glrq) - 693878.966116765) If Year(glrq) = 2051 Then chunfen = chunfen - 1If glrq = chunfen Then jr2 = "春分"Dim qingming As Dateqingming = Int(365.242254377632 * Year(glrq) - 693863.694715595) If glrq = qingming Then jr2 = "清明"Dim guyu As Dateguyu = Int(365.242150678344 * Year(glrq) - 693848.193860396)If Year(glrq) = 2045 Then guyu = guyu - 1If glrq = guyu Then jr2 = "谷雨"Dim lixia As Datelixia = Int(365.242041986455 * Year(glrq) - 693832.541539829)If Year(glrq) = 1973 Or Year(glrq) = 2035 Then lixia = lixia - 1If glrq = lixia Then jr2 = "立夏"Dim xiaoman As Datexiaoman = Int(365.241895042148 * Year(glrq) - 693816.712806842)If Year(glrq) = 2070 Then xiaoman = xiaoman - 1If glrq = xiaoman Then jr2 = "小满"Dim mangzhong As Datemangzhong = Int(365.241908822174 * Year(glrq) - 693801.095841903)If Year(glrq) = 2026 Or Year(glrq) = 2055 Or Year(glrq) = 2088 Then mangzhong = mangzhong -1If glrq = mangzhong Then jr2 = "芒种"Dim xiazhi As Datexiazhi = Int(365.242316100823 * Year(glrq) - 693786.181888162)If Year(glrq) = 2019 Or Year(glrq) = 2023 Or Year(glrq) = 2048 Or Year(glrq) = 2052 Or Year(glrq)= 2056 Or Year(glrq) = 2081 Or Year(glrq) = 2085 Or Year(glrq) = 2089 Then xiazhi = xiazhi - 1If glrq = xiazhi Then jr2 = "夏至"Dim xiaoshu As Datexiaoshu = Int(365.241837274251 * Year(glrq) - 693769.530669936)If Year(glrq) = 2078 Then xiaoshu = xiaoshu - 1If glrq = xiaoshu Then jr2 = "小暑"Dim dashu As Datedashu = Int(365.241703595146 * Year(glrq) - 693753.549346385)If glrq = dashu Then jr2 = "大暑"Dim liqiu As Dateliqiu = Int(365.241890113665 * Year(glrq) - 693738.222492901)If Year(glrq) = 2035 Or Year(glrq) = 2068 Or Year(glrq) = 2097 Then liqiu = liqiu - 1If glrq = liqiu Then jr2 = "立秋"Dim chushu As Datechushu = Int(365.242316100823 * Year(glrq) - 693723.45493336)If Year(glrq) = 2020 Or Year(glrq) = 2049 Or Year(glrq) = 2053 Then chushu = chushu - 1If glrq = chushu Then jr2 = "处暑"Dim bailu As Datebailu = Int(365.242316100823 * Year(glrq) - 693707.939588367)If glrq = bailu Then jr2 = "白露"Dim qiufen As Dateqiufen = Int(365.242085926645 * Year(glrq) - 693692.119710911)If glrq = qiufen Then jr2 = "秋分"Dim hanlu As Datehanlu = Int(365.242316100823 * Year(glrq) - 693677.304821888)If Year(glrq) = 2073 Then hanlu = hanlu - 1If glrq = hanlu Then jr2 = "寒露"Dim shuangjiang As Dateshuangjiang = Int(365.242316100823 * Year(glrq) - 693662.177281271)If glrq = shuangjiang Then jr2 = "霜降"Dim lidong As Datelidong = Int(365.242316100823 * Year(glrq) - 693647.185448183)If glrq = lidong Then jr2 = "立冬"Dim xiaoxue As Datexiaoxue = Int(365.242316100823 * Year(glrq) - 693632.293388525)If Year(glrq) = 1912 Then xiaoxue = xiaoxue - 1If glrq = xiaoxue Then jr2 = "小雪"Dim daxue As Datedaxue = Int(365.242199074074 * Year(glrq) - 693617.264427083)If Year(glrq) = 2020 Or Year(glrq) = 2053 Or Year(glrq) = 2082 Then daxue = daxue + 1If glrq = daxue Then jr2 = "大雪"Dim dongzhi As Datedongzhi = Int(365.242615913523 * Year(glrq) - 693603.343641496)If Year(glrq) = 2054 Or Year(glrq) = 2087 Then dongzhi = dongzhi + 1If glrq = dongzhi Then jr2 = "冬至一九第一天"For i = 10 To 73 Step 9IfMonth(glrq)<>12Thendongzhi=Int(365.242615913523*(Year(glrq)-1)-693603.343641496): If Year(glrq) - 1 = 2054 Or Year(glrq) - 1 = 2087 Then dongzhi = dongzhi +1If i = glrq - dongzhi + 1 ThenIf i = 10 Then jr2 = jr2 & "二九第一天": Exit ForIf i = 19 Then jr2 = jr2 & "三九第一天": Exit ForIf i = 28 Then jr2 = jr2 & "四九第一天": Exit ForIf i = 37 Then jr2 = jr2 & "五九第一天": Exit ForIf i = 46 Then jr2 = jr2 & "六九第一天": Exit ForIf i = 55 Then jr2 = jr2 & "七九第一天": Exit ForIf i = 64 Then jr2 = jr2 & "八九第一天": Exit ForIf i = 73 Then jr2 = jr2 & "九九第一天": Exit ForEnd IfNext i'公历节日--jr3If nlr = 3 Then Call gljr(glrq, jr3)'4、日期的天干地支di4bu: If nlr <> 5 Then GoTo di5buDim ganzhiB As VariantganzhiB = Array("甲子", "乙丑", "丙寅", "丁卯", "戊辰", "己巳", "庚午", "辛未", "壬申", "癸酉", "甲戌", "乙亥", "丙子", "丁丑", "戊寅", "己卯", "庚辰", "辛巳", "壬午", "癸未", "甲申", "乙酉", "丙戌", "丁亥", "戊子", "己丑", "庚寅", "辛卯", "壬辰", "癸巳", "甲午", "乙未", "丙申", "丁酉", "戊戌", "己亥", "庚子", "辛丑", "壬寅", "癸卯", "甲辰", "乙巳", "丙午", "丁未", "戊申","己酉", "庚戌", "辛亥", "壬子", "癸丑", "甲寅", "乙卯", "丙辰", "丁巳", "戊午", "己未", "庚申","辛酉", "壬戌", "癸亥")'(1)把农历年份的天干地支赋值于ngz,农历1984年是:甲子年Dim ns%, ngz$If X = Year(glrq) And glrq < lichun Then'春节后立春时,小于立春的日子为上一年:X-1ns = X - 1 - 1983ElseIf X = Year(glrq) - 1 And glrq >= lichun Then ns = X + 1 - 1983 '春节前立春时,大于等于立春的日子为下一年:X+1Elsens = X - 1983'其他日子为当年:XEnd Ifns = ns Mod 60If ns <= 0 Then ns = ns + 60 '年干支数ngz = ganzhiB(ns)'年干支'(2)把农历月份的天干地支赋值于ygzDim yfs%, ntgs%, ytgs%, ydzs%, ygzs%, ygz$If glrq < xiaohan Then'农历月份数'小寒yfs = 11ElseIf glrq < lichun Then yfs = 12'立春ElseIf glrq < jingzhe Then yfs = 1'惊蛰ElseIf glrq < qingming Then yfs = 2'清明ElseIf glrq < lixia Then yfs = 3'立夏ElseIf glrq < mangzhong Then yfs = 4'芒种ElseIf glrq < xiaoshu Then yfs = 5'小暑ElseIf glrq < liqiu Then yfs = 6'立秋ElseIf glrq < bailu Then yfs = 7'白露ElseIf glrq < hanlu Then yfs = 8'寒露ElseIf glrq < lidong Then yfs = 9'立冬ElseIf glrq < daxue Then yfs = 10'大雪Elseyfs = 11End Ifntgs = ns Mod 5: If ntgs = 0 Then ntgs = 5'年天干数(1—5)ytgs = (ntgs * 2 + yfs) Mod 10: If ytgs = 0 Then ytgs = 10'月天干数(口诀:年上起月不麻烦,月干周期为五年。

相关文档
最新文档