1
我正在製作一個宏,它將搜索一個列表並查找列表中的所有條目,這些條目中的第一個是spectraseven。這將是將這些記錄複製到每個條目的表單中。運行時錯誤'1004':應用程序定義的錯誤或對象定義的錯誤
隨着代碼到目前爲止它失敗:
運行時錯誤「1004」:應用程序定義或對象定義的錯誤。
Sub testWild()
startCell = 0
Dim FoundCell As Range
Dim LastCell As Range
Dim FirstAddr As String
cellRange = "A1:A20"
topCount = startCell
With Range("A1:A20")
Set LastCell = .Cells(.Cells.Count)
End With
Dim findString As String
findString = "spectraseven*"
Set FoundCell = Range(cellRange).Find(what:=findString, after:=LastCell)
If Not FoundCell Is Nothing Then
FirstAddr = FoundCell.Address
End If
Do Until FoundCell Is Nothing
Debug.Print FoundCell.Address
Set FoundCell = Range(cellRange).FindNext(after:=FoundCell)
Count = FoundCell.Row
Set FoundCell = Range(cellRange).FindNext(after:=FoundCell)
---> Sheets(1).Range("a" & topCount) = Sheets(1).Range("e" & Count)
topCount = topCount + 1
If FoundCell.Address = FirstAddr Then
Exit Do
End If
Loop
End Sub
的箭頭指向錯誤。
謝謝。我想我習慣於其他編程語言,從0開始 – monkthemighty
澄清,數值(整數,長,雙,單)變量從0開始在VBA中,但是,當直接在Excel中引用單元格像'Range( 「A1」)'它們從1開始。另外,當引用一個範圍內的單元格時,還必須使用1個鹼基,因此'Range(「A1:A10」)。Cells(1,1).Address = $ A $ 1' –