为什么在比较两列时会出现运行时错误?
我有一个macros应该比较两个不同单元格中的两列。 当我testing它时,它起作用了。 (请忽略德语笔记)
这两个工作表有8列,但我只是想比较第一个彼此。 我已经标记了我得到的地方
运行时间错误424
谁能帮忙?
'Objekte festlegen Dim j As Integer Dim d1 As Object Dim d2 As Object Dim d3 As Object Dim e As Range Dim shA As Worksheet Dim shB As Worksheet Set d1 = CreateObject("scripting.dictionary") Set d2 = CreateObject("scripting.dictionary") Set d3 = CreateObject("scripting.dictionary") Set shA = Worksheets(Format(Date, "dd.mm.yyyy")) Set shB = Worksheets(ActiveSheet.Index - 1) 'Füge ICM Nummern des alten Tabellenblattes Objekten zu With shB For Each e In .Cells(2, 1).Resize(Cells(Rows.Count, 1).End(3).Row).Value d1(e) = True d2(e) = True Next e End With 'Neue und alte ICM Nummern bestimmen With shA
For Each e In .Cells(2,1).Resize(Cells(Rows.Count,2).End(3).Row).Value
If (d2(e)) * (d1.exists(e)) Then d1.Remove e If Not d2(e) Then d3(e) = True Next e
'Bestimme Anzahl zu erstellender Zeilen If d1.Count > d3.Count Then Set j = d1.Count Else: Set j = d3.Count End If
'Füge Zellen ein Range("1:1").Resize(j).Insert Shift:=xlDown, Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove 'Objekte transponieren und einfügen in aktuelles Tabellenblatte unter ICM Abzug On Error Resume Next .Cells(1, 10).Resize(d1.Count) = Application.Transpose(d1.keys) .Cells(1, 11).Resize(d3.Count) = Application.Transpose(d3.keys) On Error GoTo 0 End With
你想循环一个Range
,而不是Value
。
此外,您需要With shA
限定您的Cells
和With shA
,方法是添加.
作为前缀。
更改:
For Each e In .Cells(2, 1).Resize(Cells(Rows.Count, 2).End(3).Row).Value
至:
For Each e In .Cells(2, 1).Resize(.Cells(.Rows.Count, 2).End(3).Row)