找不到任何东西

我无法从其内部的同一列中find条目。 为什么? 我的代码有什么问题? 我得到types不兼容的错误,因为它找不到第一个条目。

Dim Namensspalte As Range, firstEntry As Range, secondEntry As Range Set Namensspalte = iMAw.Range("E2:E1700") With Namensspalte For Each c In Namensspalte Set firstEntry = .Find(c, xlValues, xlWhole) If Not firstEntry Is Nothing Then firstEntry.Offset(0, 3).Value = firstEntry.Offset(0, -4).Value Else MsgBox "Error" End If Set secondEntry = .FindNext(c) If Not secondEntry Is Nothing Then secondEntry.Offset(0, 4).Value = secondEntry.Offset(0, -4).Value End If Next End With 

这应该正常工作:

 Sub test_HausUkrop() Dim Namensspalte As Range, firstEntry As Range, secondEntry As Range, _ c As Range, FirstAddress As String Set Namensspalte = iMAw.Range("E2:E1700") With Namensspalte For Each c In .Cells Set firstEntry = .Find(What:=c.Value2, _ After:=.Cells(1, 1), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByColumns, _ SearchDirection:=xlNext, _ MatchCase:=False, _ SearchFormat:=False) If Not firstEntry Is Nothing Then FirstAddress = firstEntry.Address firstEntry.Offset(0, 3).Value = firstEntry.Offset(0, -4).Value Set secondEntry = .FindNext(firstEntry) 'Look until you find again the first result If Not secondEntry Is Nothing Then If secondEntry.Address <> FirstAddress Then secondEntry.Offset(0, 4).Value = secondEntry.Offset(0, -4).Value Else End If Else End If Else MsgBox "Error" End If Next c End With End Sub