Sub test2()
Sheets("系統檔").ComboBox1.Clear
For i = 1 To 7
Sheets("系統檔").ComboBox1.AddItem Date - i
Next
End Sub
如果要有0
Sub test3()
Sheets("系統檔").ComboBox1.Clear
For i = 1 To 7
Sheets("系統檔").ComboBox1.AddItem Format(Date - i, "yyyy/mm/dd")
Next
End Sub作者: av8d 時間: 2022-8-17 13:59
For i = 1 To 7
If WeekdayName(Weekday(Date - i)) <> "星期六" Then
Sheets("系統檔").ComboBox1.AddItem Date - i
End If
Next
以上單一條件星期六省略,則沒問題,但是以下雙條件,則出現了雙條件都不會被省略的問題。
For i = 1 To 7
If WeekdayName(Weekday(Date - i)) <> "星期六" Or WeekdayName(Weekday(Date - i)) <> "星期日" Then
Sheets("系統檔").ComboBox1.AddItem Date - i
End If
Next
For i = 7 To 1 Step -1
If WeekdayName(Weekday(Date - i)) = "星期二" Or WeekdayName(Weekday(Date - i)) = "星期五" Then
Sheets("系統檔").ComboBox1.AddItem Date - i
End If
Next
For i = 1 To 7
If WeekdayName(Weekday(Date + i)) = "星期二" Or WeekdayName(Weekday(Date + i)) = "星期五" Then
Sheets("系統檔").ComboBox1.AddItem Date + i
End If
Next作者: singo1232001 時間: 2022-8-17 22:37
Sub test()
Sheets("系統檔").ComboBox1.Clear
For i = 7 To -7 Step -1
wdi = Weekday(Date - i, 2)
If wdi = 2 Or wdi = 5 Then
Sheets("系統檔").ComboBox1.AddItem Format(Date - i, "yyyy/m/d") & " " & WeekdayName(wdi, , 2)
'Sheets("系統檔").ComboBox1.AddItem Format(Date - i, "yyyy/m/d") '沒星期幾
End If
Next
End Sub
Sub test()
Set Sc = Sheets("系統檔").ComboBox1
Sc.Clear
For i = 11 To -11 Step -1
w = Weekday(Date - i, 2)
If w >= 1 And w <= 5 Then Sc.AddItem Format(Date - i, "yyyy/m/d") & " " & WeekdayName(w, 1, 2)
Next
Select Case Weekday(Date, 2)
Case Is = 1, 5: Sc.Text = Format(Date + 4, "yyyy/m/d") & " " & WeekdayName(Weekday(Date + 4, 2), 1, 2)
Case Is = 2, 6: Sc.Text = Format(Date + 3, "yyyy/m/d") & " " & WeekdayName(Weekday(Date + 3, 2), 1, 2)
Case Is = 3: Sc.Text = Format(Date + 2, "yyyy/m/d") & " " & WeekdayName(Weekday(Date + 2, 2), 1, 2)
Case Is = 4: Sc.Text = Format(Date + 1, "yyyy/m/d") & " " & WeekdayName(Weekday(Date + 1, 2), 1, 2)
End Select
End Sub
1. Sheets("系統檔").ComboBox1 可以縮寫成你想要到名稱
2.多條件判斷 可以練習使用select case 當然if也沒問題
會用的原因是 當多條件內部 未來出現多層判斷時 可以select case + if then 搭配 比較好分辨