我在调试我编写的代码时遇到问题。它运行良好,直到某个点,然后停止并显示:运行时错误1004应用程序定义或对象定义的错误。Excel VBA:错误1004应用程序定义错误或对象定义错误
我很久没写VBA了,所以我的代码可能是一团糟=)。
的问题似乎是:见注释“生成UID为当前进出口
'Sheet Definitions
strSourceSheet = "MasterReport"
strComponentSheet = "UniqueIdComponents"
'defines row where data starts
intEntryCount = 2
intImpCount = 0
'determine maximum number of rows for both sheets
lngMaxRowSS = ThisWorkbook.Sheets(strSourceSheet).UsedRange.SpecialCells(xlCellTypeLastCell).Row
lngMaxRowCS = ThisWorkbook.Sheets(strComponentSheet).UsedRange.SpecialCells(xlCellTypeLastCell).Row
'Run until there are no more entries
For intEntryCount = 2 To lngMaxRowSS
'Prevents to overwrite existing UIDs
If ThisWorkbook.Sheets(strSourceSheet).Range("BP" & intEntryCount) = "" Then
'Recieve next imperative on the Source List to find according UID Components
strSourceImperative = ThisWorkbook.Sheets(strSourceSheet).Range("A" & intEntryCount)
'Run until no new Imp UID is defind
For intImpCount = 11 To lngMaxRowCS
'Location of Imps on Component Sheet
strComponentImperative = ThisWorkbook.Sheets(strComponentSheet).Range("C" & intImpCount)
' If the Source Imp = Component Imp then we create a UID for that Source IP
If strSourceImperative = strComponentImperative Then
'Assign Column to UID component in order to find the Column in the MasterReport
strUIDComponent1 = ThisWorkbook.Sheets(strComponentSheet).Range("D" & intImpCount)
strUIDComponent2 = ThisWorkbook.Sheets(strComponentSheet).Range("E" & intImpCount)
strUIDComponent3 = ThisWorkbook.Sheets(strComponentSheet).Range("F" & intImpCount)
strUIDComponent4 = ThisWorkbook.Sheets(strComponentSheet).Range("G" & intImpCount)
strUIDComponent5 = ThisWorkbook.Sheets(strComponentSheet).Range("H" & intImpCount)
strUIDComponent6 = ThisWorkbook.Sheets(strComponentSheet).Range("I" & intImpCount)
strUIDComponent7 = ThisWorkbook.Sheets(strComponentSheet).Range("J" & intImpCount)
'Generate UID for the Current Imp
strUID = ThisWorkbook.Sheets(strSourceSheet).Range(strUIDComponent1 & intEntryCount) _
& ThisWorkbook.Sheets(strSourceSheet).Range(strUIDComponent2 & intEntryCount) _
& ThisWorkbook.Sheets(strSourceSheet).Range(strUIDComponent3 & intEntryCount) _
& ThisWorkbook.Sheets(strSourceSheet).Range(strUIDComponent4 & intEntryCount) _
& ThisWorkbook.Sheets(strSourceSheet).Range(strUIDComponent5 & intEntryCount) _
& ThisWorkbook.Sheets(strSourceSheet).Range(strUIDComponent6 & intEntryCount) _
& ThisWorkbook.Sheets(strSourceSheet).Range(strUIDComponent7 & intEntryCount)
'Writes UID into MasterReport
'ThisWorkbook.Sheets(strSourceSheet).Range("BP" & intEntryCount) = strUID
'Test Writes
ThisWorkbook.Sheets("Test").Range("A" & intEntryCount) = strUID
'If the Source Imp = Component Imp then we created a UID for that Source IP
End If
'If the two Source Imp <> Component Imp, go to next row on Component sheet and compare again
Next intImpCount
'Prevented to overwrite existing UIDs
End If
Next intEntryCount
的情况下我得到错误的组件是A,M,N,O,BK‘’ ,“”和入口计数是5718.它写5718条目很好,然后显示错误。
任何想法?
在此先感谢您的帮助!
你已经张贴不作任何意义的代码。也许你应该发布更多的代码,并描述你试图用它实现的目标。 –
以下是它的作用: strUID是由许多单元格值组成的唯一ID。这些值可能会有所不同,具体取决于用户选择多少个和哪些组件(列)。 由于组件的值存储在单元格中,我使用strUIDComponent来告诉我哪个列和intEntryCount是哪一行。 我通过将多个单元格一起添加(请参阅代码)来创建strUID,然后将其打印在不同的工作表中。 – Ergo