我相當精通Excel VBA(有很多在線幫助!!)......但是我偶然發現了一個讓我完全陷入困境的問題。Excel - 使用基於用戶輸入的日期填充列
我正在爲項目計劃創建甘特圖。我的問題是,我希望讓用戶指定項目開始日期和項目結束日期,然後讓電子表格填充從開始日期到結束日期的列。
請參閱基本佈局:
我已經見底與InputBoxes
Sub Set_Project_Start_Date()
' Written 2nd August 13
' P.J. Callaghan
'
ActiveSheet.Select
Dim projStartDate
showInputBox_Start:
projStartDate = Application.InputBox("Please enter Project Start Date" & Chr(10) & "Must be a Monday" & Chr(10) & "Format is: dd/mm/yyyy")
' Set Message Box such that clicking cancel ends the sub-routine for projStartdate variable
If projStartDate = False Then
MsgBox "You clicked the Cancel button, Input Box will close.", 64, "Cancel was clicked."
Exit Sub
ElseIf projStartDate = "" Then
MsgBox "You must click Cancel to exit.", 48, "You clicked Ok but entered nothing."
GoTo showInputBox_Start
Else
MsgBox "You entered " & projStartDate & ".", 64, "Please click OK to resume."
Range("c6").Select
With Selection
.Value = projStartDate
.NumberFormat = "dd-mmm-yy"
End With
Range("e10").Select
With Selection
.Value = projStartDate
.NumberFormat = "dd-mmm-yy"
.Orientation = 90
End With
End If
End Sub
Sub Set_Project_End_Date()
' Written 2nd August 13
' P.J. Callaghan
'
ActiveSheet.Select
Dim projEndDate
showInputBox_End:
projEndDate = Application.InputBox("Please enter Project End Date" & Chr(10) & "Must be a Monday" & Chr(10) & "Format is: dd/mm/yyyy")
' Set Message Box such that clicking cancel ends the sub-routine for projStartdate variable
If projEndDate = False Then
MsgBox "You clicked the Cancel button, Input Box will close.", 64, "Cancel was clicked."
Exit Sub
ElseIf projEndDate = "" Then
MsgBox "You must click Cancel to exit.", 48, "You clicked Ok but entered nothing."
GoTo showInputBox_End
Else
MsgBox "You entered " & projEndDate & ".", 64, "Please click OK to resume."
Range("c7").Select
With Selection
.Value = projEndDate
.NumberFormat = "dd-mmm-yy"
End With
End If
End Sub
位,我只能和正在編寫代碼從起始日期來填充到最終用戶輸入僅限日期。我肯定這肯定是某種循環安排......至今我還沒有弄明白。
我想知道你們中的任何人是否可以提出解決方案?
由於提前,
保羅
你的意思是「讓電子表格填充從開始日期到結束日期的列」。 – Tarik
嗨Tarik,我希望電子表格用用戶定義的項目開始日期(變量projStartDate)填充單元格e10,然後用項目開始日期到項目結束日期的每個日期填充第10行中的所有後續列。我希望宏一旦單元格值達到項目結束日期(變量projEndDate)就停止填充。我正在查找的功能是一個圖表,範圍從用戶定義的開始日期到用戶定義的項目結束日期。 –