判断平年闰年vba代码怎么写(vba判断是否为闰年)

http://www.itjxue.com  2023-03-17 13:47  来源:未知  点击次数: 

用Excel,vba编程,键盘接收一个年份值,判断它是闰年还是平年怎么做?

Sub?aa()

a?=?Sheet1.Cells(1,?1)

If?a?Mod?4?=?0?Then

Sheet1.Cells(1,?2)?=?366

Else

Sheet1.Cells(1,?2)?=?365

End?If

End?Sub

整除4是否为零来判断闰年还是平年。

用VBA判断是否闰年

Sub CommandButton1_Click()

Dim y,s

y = [a1]

If (y Mod 4 = 0 Or y Mod 400 = 0) And y Mod 100 0 Then

s= "闰年"

Else

s= "平年"

End If

[a2]=y "年是" s

End Sub

Excel中填写计算闰年平年的vba代码

用下面代码试试

Private Sub togglebutton6_click()

n = InputBox("输入年份:")

Dim rn(1904 To 2104)

For i = 1904 To 2100 Step 4

? rn(i) = "闰年"

? rn(i + 1) = "平年"

? rn(i + 2) = rn(i + 1): rn(i + 3) = rn(i + 1)

Next

MsgBox (n "年是" rn(n))

End Sub

(责任编辑:IT教学网)

更多

推荐MYSQL文章