我正在尝试:
如果在sheet1和sheet2中,sheet1中的列 E 和sheet2中的列 F 上的单元格具有相同的值,
然后将值从sheet2 column A row x 复制到sheet2 column P row y。
行 x 和 y 是每个工作表上相同值的位置。
Sub ccopiazanrfact()
Dim camion As Worksheet
Dim facturi As Worksheet
Set camion = ThisWorkbook.Sheets("B816RUS")
Set facturi = ThisWorkbook.Sheets("EVIDENTA FACTURI")
Dim nrcomanda As String
Dim nrfactura As String
For a = 2 To facturi.Range("F" & Rows.Count).End(xlUp).Row
nrcomanda = facturi.Range("F" & a).Value
For b = 4 To camion.Range("E" & Rows.Count).End(xlUp).Row
If camion.Range("E" & b).Value = facturi.Range("F" & a).Value Then
camion.Range("P" & b) = facturi.Range("A" & a).Value
Exit For
End If
Next b
Next a
End Sub
字符串
4条答案
按热度按时间zf9nrax11#
我建议使用数组来实现你想要的。在范围内嵌套循环会使其非常慢。这就是你要尝试的吗?(未经测试)。由于我没有测试过它,我建议在测试此代码之前备份数据。
我已经注解了代码。但是如果你仍然有问题或者在下面的代码中发现了错误,那么就直接问吧。
字符串
s3fp2yjn2#
最后,我想出了这个,并立即工作,得到的所有数据填充在一眨眼的功夫。当我第一次尝试它时,我以为我忘记在运行代码之前清除数据:
字符串
4xy9mtcn3#
请测试下一个代码。它应该非常快,使用数组和
Find
函数:字符串
请在测试后发送一些反馈…
o7jaxewo4#
VBA查询:使用数组和字典
字符串