当前为我公司实现一个突出订单异常的项目,我编写了此VBA代码,以便比较订单状态以及当前日期和订单日期之间的日期差异。 CSV上的日期如下:“ 2019-05-06 3:11 pm”
当我将宏插入按钮并单击时,出现以下错误:“编译错误,未定义Sub或函数”,调试器光标指向“ Sub Problem()” ...
我希望你能帮助我!在此先感谢:)
这是我的代码:
Sub Problem()
Dim orderDate As Date
Dim difDate
Dim statusToUse As Range
Set statusToUse = Range("C2:C100")
Dim statusCell As Range
Dim a As String
a = "accepted"
Dim s As String
s = "shipped"
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim m As Integer
Dim dateToUse As Range
Set dateToUse = Range("D2:D100")
Dim dateCell As Range
Dim currentDate As String
currentDate = Date
y = Split(Split(Range("A1").Value, ":")(1), "-")
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For Each statusCell In statusToUse.Areas
For Each dateCell In dateToUse.Areas
orderDate = DateValue(Join(Array(y(2), y(1), y(0)), "-"))
difDate = DateDiff("d", currentDate, orderDate)
If status = a And difDate <= 7 Then
status.Interior.ColorIndex = 46
i = i + 1
ElseIf status = a And difDate <= 2 Then
status.Interior.ColorIndex = 27
j = j + 1
ElseIf status = a And difDate > 7 Then
status.Interior.ColorIndex = 3
k = k + 1
ElseIf status = s Then
status.Interior.ColorIndex = 10
l = l + 1
Else
m = m + 1
End If
i = i - j
Next dateCell
Next statusCell
MsgBox "There are" + i + "risky orders"
End Sub
答案 0 :(得分:0)
当子目录位于工作表中而不是在新模块中时,通常会发生此错误。
如果已经在模块中,请检查模块名称是否与“ module1”不同。