在Excel中清洁代码?

作为一名前程序员,我喜欢清洁,可维护和文档化的代码。

作为一名项目经理,我不得不不时地做出复杂的卓越,并且想用我编写程序的方式来写“干净”的公式。

  1. (How)我可以将“注释”添加到(多行)公式中吗?

  2. (如何)我可以“命名”一个(细胞相关)公式并重用它? (例如用参数写成vb(甚至f#)函数)

例1:而不是

=IF(AND(L$11+(L$13-1)*7>=$C15;L$11+(L$13-1)*7<$D15);VLOOKUP($A15;RessourcePlan;12+$E15;WRONG);0) 

我想写:

 // check if this columns (L) date is inbetween startdate (Col C) and enddate (Col D) =IF (AND(L$11+(L$13-1)*7>=$C15;L$11+(L$13-1)*7<$D15); // then select the the utilisation (12+E15) for the resp. team from the resource plan VLOOKUP($A15;RessourcePlan;12+$E15;WRONG); // else default to 0 0 ) //ENDIF 

而不是example1,我可能会写一个用户定义函数(UDF)

 Function Utilization(thisDate As Date, task As String) As Double ... // clean VB or F# code End Function 

然后写

 =Utilization(L11,A15) 

作为一个前function程序员,我想出了用户定义的函数给出了我的问题。

请注意以下几点:

  • 我只写“纯”的math函数,将参数映射到结果,没有状态变化,input/输出,for循环或类似的参数。 (至less我有这个想法,“让”和VBA显然不是“纯”的)
  • 单元格引用和自动完成是在表单中完成的(excel在这里很强大)
  • 常量在名为“常量”的特殊表中定义为命名范围

鉴于一个任务,预计工作量和开始和结束date,我需要多less人工鱼粉? => 100%意味着一个人需要在这个全职工作(假设她正在工作x天每周,固定在常数)

 Public Function util(ByVal startDate As Date, ByVal endDate As Date, ByVal estimation As Double) As Double Dim duration As Integer Let duration = DateDiff("d", startDate, endDate) Dim weeks As Double Let weeks = duration / 7 Dim pdays As Integer Let pdays = weeks * [daysPerWeek] util = estimation / pdays End Function 

由于我有许多任务和很多团队在工作,所以我想知道我需要一个团队从一个团队中获得多less人。 下面的函数从上面重用函数。 注意复杂的Vlookup调用的可读名称和对我的实际项目计划的“BaseLine1”的引用。 将其扩展到其他场景将是非常容易的。

 Public Function currentUtil(currentDate As Date, id As String, team As Integer) As Double Dim result As Double Let startDate = Application.WorksheetFunction.VLookup(id, [BaseLine1], 11, 0) Let endDate = Application.WorksheetFunction.VLookup(id, [BaseLine1], 12, 0) Let estimation = Application.WorksheetFunction.VLookup(id, [BaseLine1], 5 + team, 0) If (currentDate >= startDate And currentDate < endDate) Then result = util(startDate, endDate, estimation) Else result = 0 End If currentUtil = result End Function 

最后我以下面的方式使用它:我有一个主表,包括所有的任务,包括他们的date和每个团队的估计的努力。 在另一张纸上,我有横向的星期和垂直的每个团队的任务。 在单元格中,我使用函数“currentUtil”并使用自动完成和条件格式来获得关于计划的分析视图。

最后我有和以前一样的结果,但是更方便和可维护的forms。