比较两列时为什么会出现运行时错误?

菲奥普斯

我有一个宏,应该比较两个不同单元格中的两个列。当我测试它时,它开始工作。(请忽略德语注释)

这两个工作表都有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

对于.Cells(2,1).Resize(Cells(Rows.Count,2).End(3).Row).Value中的每个e

        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
Shai Rado

您要遍历而Range不是Value

另外,你需要有资格的CellsRows.CountWith 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)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么会出现运行时错误?

为什么会出现访问冲突运行时错误?

释放内存时为什么会出现运行时错误?

为什么每当我将API密钥放入build.gradle时都会出现运行时错误?

为什么这段代码在中间计算时会出现运行时错误?

为什么在StackBlitz上运行时,我的Angular应用程序会出现错误?

为什么会出现运行时错误:向量擦除迭代器超出范围

为什么在为 char 指针赋值时会出现运行时错误?

为什么即使在声明向量的大小之后也会出现运行时错误?

从 MS Word 文档中读取单选按钮值时,为什么会出现“运行时错误‘91’:对象变量或块变量未设置”?

为什么在运行简单的docker映像时出现oci运行时错误?

为什么会出现运行时错误58-在VBA中复制文件时文件已经存在?

为什么会出现这种使用泛型不会抛出运行时或编译时的异常?

为什么我在 Windows 中使用 python 进行多处理时出现运行时错误?

为什么在struct中使用字符串时出现运行时错误

为什么在Codechef中提交此代码时出现运行时错误(SIGABRT)?

为什么在读取文件时出现运行时错误

为什么在联机提交此代码时出现运行时错误?(jdk 1.7)

为什么该程序在运行时出现错误

为什么io.WriterString出现运行时错误?

为什么我的代码出现运行时错误?

为什么在程序运行时会出现偶尔出现的NPE?

运行此文件时,为什么会出现doctest错误?

在运行时垂直调整Frame大小后,为什么JRadioButtons会出现故障?

为什么我的通用 StatefulWidget 类在运行时会出现 TypeError?

为什么从MEL访问ArrayList的大小时会出现运行时异常?

使用非可比较类创建TreeSet:为什么运行时异常而不是编译时错误?

为什么在新计算机上访问Firestore时会出现“紧急:运行时错误:无效的内存地址或nil指针取消引用”?

Word- VBA-为什么会出现运行时错误451“属性让过程未定义且属性获取过程未返回对象”?