我相当精通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)就停止填充。我正在查找的功能是一个图表,范围从用户定义的开始日期到用户定义的项目结束日期。 –