1.用vba的case函式
開啟MS Excel,按下alt+F11,複製貼上下列程式碼:
Sub 測吉祥()
Dim a As Integer
a = InputBox("請輸入:")
Select Case a
Case 1, 3, 5, 7, 8, 11
MsgBox "大吉"
Case 6, 17, 26, 27, 29
MsgBox "中吉"
Case 2, 4, 9, 10, 12
MsgBox "不吉祥"
Case Else
MsgBox " 無效"
End Select
End Sub
如圖
按F5執行就行了。
2.直接使用IF函式
在表格A1處輸入數字,在表格A2處複製貼上下列程式碼
=IF(OR(A1=1,A1=3,A1=5,A1=7,A1=8,A1=11),"大吉",IF(OR(A1=6,A1=17,A1=26,A1=27,A1=29),"中吉",IF(OR(A1=2,A1=4,A1=9,A1=10,A1=12),"不吉祥","無效")))
1.用vba的case函式
開啟MS Excel,按下alt+F11,複製貼上下列程式碼:
Sub 測吉祥()
Dim a As Integer
a = InputBox("請輸入:")
Select Case a
Case 1, 3, 5, 7, 8, 11
MsgBox "大吉"
Case 6, 17, 26, 27, 29
MsgBox "中吉"
Case 2, 4, 9, 10, 12
MsgBox "不吉祥"
Case Else
MsgBox " 無效"
End Select
End Sub
如圖
按F5執行就行了。
2.直接使用IF函式
在表格A1處輸入數字,在表格A2處複製貼上下列程式碼
=IF(OR(A1=1,A1=3,A1=5,A1=7,A1=8,A1=11),"大吉",IF(OR(A1=6,A1=17,A1=26,A1=27,A1=29),"中吉",IF(OR(A1=2,A1=4,A1=9,A1=10,A1=12),"不吉祥","無效")))