步调公式:减去不同单元格中的日期并比较数字

Pacing formula: Subtract dates in different cells and compare number

我有一个 excel 电子表格(没有设置行数),G 列为开始日期,H 列为结束日期,I 列为售出数量,以及J 列中可用的总单位数。我想创建一个宏:

1) 从结束日期减去开始日期得到总天数

2) 用今天的日期减去开始日期得到总天数 运行

3) 将总天数运行除以总天数为 获取天数百分比 运行

4) 将售出的总单位数除以可获得的总单位数 售出百分比

5) 比较总天数 运行 百分比与售出单位百分比:

A) 如果售出单位的百分比等于或大于 天 运行,在 K

栏写 "Ahead of Pacing"

B) 如果售出单位百分比小于天数百分比 运行, 在 K

列中写入 "Behind Pacing"

*** 更新:我提供了一些图片链接,说明我希望电子表格如何工作(抱歉,我没有足够的 post 图片的信誉点数):

之前:

https://www.dropbox.com/s/f35lx1gtsq296s2/Sheet1.jpg?dl=0

之后:

https://www.dropbox.com/s/clnnxm6eteav5kz/Sheet2.jpg?dl=0

谢谢

好吧,我想我会再次回答我自己的问题...也许其他人会觉得它有用。令人沮丧的是,我似乎永远无法在这个论坛上得到直接的答案。到目前为止,我已经有一位成员问我正在使用什么程序(当我在我的问题中明确提到电子表格时......这应该清楚地表明我正在使用 Excel)......还有另一位成员斥责我就像学生的老师(但没有提供有用的信息)。我宁愿得不到任何回应,也不愿忍受无法 understand/read 提问的人的这些无礼言论。我知道这不是我的问题,因为我过去从 mrexcel.com、rondebruin 和其他几个论坛获得帮助时没有遇到任何问题(看起来我从现在开始会回到这些论坛)。无论如何,抛开所有抱怨,这是我正在寻找的代码:

Sub Pacing()
' Reps must put a date in or it breaks the macro (can't use NA or Month Names)
Dim i As Long
Dim numberOfRows As Long

With Application
    .ScreenUpdating = False
    .EnableEvents = False
End With

Worksheets("Pacing").Activate

numberOfRows = Cells(Rows.Count, "D").End(xlUp).Row

' Bottom Rows first
Cells(numberOfRows, 11).Value = Cells(numberOfRows, 8).Value - Cells(numberOfRows, 7).Value
Cells(numberOfRows, 12).Value = Now() - Cells(numberOfRows, 7).Value
Cells(numberOfRows, 13).Value = Cells(numberOfRows, 12).Value / Cells(numberOfRows, 11).Value
Cells(numberOfRows, 14).Value = Cells(numberOfRows, 9).Value / Cells(numberOfRows, 10).Value

If Cells(numberOfRows, 14).Value = Cells(numberOfRows, 13).Value Then
 Cells(numberOfRows, 15).Value = "Pacing"
 Cells(numberOfRows, 15).Interior.Color = RGB(0, 180, 10)
ElseIf Cells(numberOfRows, 14).Value > Cells(numberOfRows, 13).Value Then
 Cells(numberOfRows, 15).Value = "Ahead of pacing"
 Cells(numberOfRows, 15).Interior.Color = RGB(0, 180, 10)
ElseIf Cells(numberOfRows, 14).Value < Cells(numberOfRows, 13).Value Then
 Cells(numberOfRows, 15).Value = "Behind pacing"
 Cells(numberOfRows, 15).Interior.Color = RGB(182, 0, 24)
End If

 If Cells(numberOfRows, 10).Value > Cells(numberOfRows, 5) Then
 Cells(numberOfRows, 16).Value = "Warning: Total Cap Greater Than Goal"
 Cells(numberOfRows, 16).Font.Color = RGB(182, 0, 24)
 ElseIf Cells(numberOfRows, 10).Value < Cells(numberOfRows, 5) Then
 Cells(numberOfRows, 16).Value = "Warning: Total Cap Lower Than Goal.  Speak with Rep"
 Cells(numberOfRows, 16).Font.Color = RGB(182, 0, 24)
End If

'Continue Up

For i = numberOfRows To 3 Step -1


If Cells(i, 4).Interior.Color = RGB(192, 192, 192) Then
Cells(i, 11).Value = Cells(i, 8).Value - Cells(i, 7).Value
Cells(i, 12).Value = Now() - Cells(i, 7).Value
Cells(i, 13).Value = Cells(i, 12).Value / Cells(i, 11).Value
If Cells(i, 10) = 0 Then
Cells(i, 14).Value = 0
Else
Cells(i, 14).Value = Cells(i, 9).Value / Cells(i, 10).Value
End If
  If Cells(i, 14).Value = Cells(i, 13).Value Then
 Cells(i, 15).Value = "Pacing"
 Cells(i, 15).Interior.Color = RGB(0, 180, 10)
 ElseIf Cells(i, 14).Value > Cells(i, 13).Value Then
 Cells(i, 15).Value = "Ahead of pacing"
 Cells(i, 15).Interior.Color = RGB(0, 180, 10)
 ElseIf Cells(i, 14).Value < Cells(i, 13).Value Then
 Cells(i, 15).Value = "Behind pacing"
 Cells(i, 15).Interior.Color = RGB(182, 0, 24)
 End If

 If Cells(i, 10).Value > Cells(i, 5) Then
 Cells(i, 16).Value = "Warning: Total Cap Greater Than Goal"
 Cells(i, 16).Font.Color = RGB(182, 0, 24)
 ElseIf Cells(i, 10).Value < Cells(i, 5) Then
 Cells(i, 16).Value = "Warning: Total Cap Lower Than Goal.  Speak with Rep"
 Cells(i, 16).Font.Color = RGB(182, 0, 24)
 End If

 End If
 Next i

 End Sub

同样,希望这至少能对其他人有所帮助...在 运行 宏之后我仍然需要处理一些格式,但除此之外它可以完成工作。