我在調試我編寫的代碼時遇到問題。它運行良好,直到某個點,然後停止並顯示:運行時錯誤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