我有以下问题。当我在下面运行代码时,我得到了由该宏创建的最多 114 行的正确结果,然后它就停止了。我收到错误消息“应用程序定义或对象定义错误”,它指向这行代码。
Range("O" & (i + 1)) = reportDate((i + 5) Mod 6)
谁能帮我找出原因。这是代码。感谢您的帮助。
Sub hmm()
Application.ScreenUpdating = False
Dim zakres As Integer
Dim rfiNumber(5) As String
Dim reportDate(5) As Date
Dim reportName(5) As String
Dim formName(5) As String
Dim rest(7) As String
Dim j As Integer
Dim item As String
Dim l As Integer
Workbooks("EAP_ZESTAWIENIE_pits+covers.xls").Activate
Worksheets("COVER").Select
zakres = Application.WorksheetFunction.CountA(Range("I:I"))
formName(0) = "MDT.CV.CDQ.0204"
formName(1) = "MDT.CV.CDQ.0205"
formName(2) = "MDT.CV.CDQ.0207"
formName(3) = "MDT.CV.CDQ.0801"
formName(4) = "MDT.CV.CDQ.0802"
formName(5) = "MDT.CV.CDQ.0803"
rest(0) = "CV"
rest(1) = "'08"
rest(2) = "'00"
rest(3) = "'0005"
rest(4) = "F17162"
rest(5) = "S001"
rest(6) = "PEK001"
rest(7) = "CV-0800"
j = 1
For i = 1 To (zakres - 2) * 3
If (((i + 6) Mod 6) = 1) Then
Worksheets("COVER").Select
item = Range("A" & (2 * j + 1))
itemDescription = Range("S" & (2 * j + 1))
rfiNumber(0) = Range("B" & (2 * j + 1))
rfiNumber(1) = Range("C" & (2 * j + 1))
rfiNumber(2) = " "
rfiNumber(3) = " "
rfiNumber(4) = Range("K" & (2 * j + 1))
rfiNumber(5) = Range("M" & (2 * j + 1))
reportDate(0) = Range("E" & (2 * j + 1))
reportDate(1) = Range("E" & (2 * j + 1))
reportDate(2) = Range("E" & (2 * j + 1))
reportDate(3) = Range("E" & (2 * j + 1))
reportDate(4) = Range("L" & (2 * j + 2))
reportDate(5) = Range("N" & (2 * j + 2))
reportName(0) = Range("F" & (2 * j + 1))
reportName(1) = Range("G" & (2 * j + 1))
reportName(2) = Range("H" & (2 * j + 1))
reportName(3) = Range("J" & (2 * j + 1))
reportName(4) = Range("L" & (2 * j + 1))
reportName(5) = Range("N" & (2 * j + 1))
j = j + 1
End If
Worksheets("import").Select
Range("A" & (i + 1)) = rest(4)
Range("B" & (i + 1)) = rest(5)
Range("C" & (i + 1)) = item
Range("D" & (i + 1)) = itemDescription
Range("F" & (i + 1)) = rest(6)
Range("G" & (i + 1)) = rest(7)
Range("H" & (i + 1)) = rest(0)
Range("I" & (i + 1)) = rest(1)
Range("J" & (i + 1)) = rest(2)
Range("K" & (i + 1)) = "'000" & ((i + 5) Mod 6) + 1
Range("L" & (i + 1)) = formName((i + 5) Mod 6)
Range("M" & (i + 1)) = rfiNumber((i + 5) Mod 6)
Range("N" & (i + 1)) = "CertCode" & "CV08000" & (((i + 5) Mod 6) + 1) & reportName((i + 5) Mod 6)
Range("O" & (i + 1)) = reportDate((i + 5) Mod 6)
Next i
End Sub