gpt4 book ai didi

vba - 找不到我的代码崩溃的原因

转载 作者:行者123 更新时间:2023-12-02 22:42:35 25 4
gpt4 key购买 nike

我编写此代码是为了比较 A 列和 B 列,每当我有类似的值时,例如 如果列 A = B显示 A、B, E、F 和 G 中的 C 如下图所示:

enter image description here

这是我正在使用的代码:

Option Explicit

Sub Comparatif_Release()
Dim t1, t2, c
Dim d As Object
Dim i&, j&, l&
Dim f As Worksheet
Range("e1:g110000").Select
Selection.ClearContents

Set f = Sheets("Sheet1")
With f

t1 = .Range("a1:a10000").Value
t2 = .Range("b1:c10000").Value
End With

Set d = CreateObject("Scripting.Dictionary")
For i = LBound(t1) To UBound(t1)
For j = LBound(t2) To UBound(t2)
If t1(i, 1) = t2(j, 1) Then
d(t1(i, 1) & ":" & t2(j, 1) & ":" & t2(j, 2)) = d(t1(i, 1) & ":" & t2(j, 1) & ":" & t2(j, 2))

End If
Next j
Next i

With f
i = 1
For Each c In d.Keys
.Cells(i, "E").Resize(, 3).Value = Split(c, ":")

i = i + 1
Next c
End With

End Sub

最佳答案

使用这些公式并过滤掉它们。它应该有效。迟到的帖子,但以防万一。

In column E1 :  =IF(A1=B1,A1,"")
In column F1 : =IF(E1<>"",B1,"")
In Column G1 : =If(E1<>"",C1,"")

关于vba - 找不到我的代码崩溃的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38048796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com