VBA:search一个值,replace不同列中的值,但同一行
在列BI中有零件号,在列C1中有序列号,在EI列中有每个零件/序列号组合的最近检验date。 我需要将检查date更新为另一个单元格中引用的新date。 我试图添加一个图像,但它不会让我。 我将尝试重新创build下面的Excel图像:
例:
BCDE
部件号 ___________ 序列号 ________________ 检查date
75750-0001-0000 ___________ 0002 ______________________ 9/15/2014
更新信息:
OPQ
部件号 ___________ 序列号 _______ 检查date
75750-0001-0000 ___________ 0004 _______________ 2015年8月24日
在O5有一个零件号码,在P5我有一个序列号,Q5我有该部分/序列的检查date。 我需要点击一个button,让检查date更新列表中的正确部分/序列号。 (实际的列表要大得多,所以手动操作会非常耗时)。 没有重复或类似的东西。 任何帮助将不胜感激。
这里的想法是做一个双重循环。 search正确的行并更新date。
Dim rng as Range Dim rngInspection as Range Set rng = Range("B2:EX") -- Range of the left table Set rngInspection = Range("O2:P5") -- Range of the right table For Each rowInspection In rngInspection.Rows Dim part as string, serial as string, inspectionDate as String part = rowInspection.Cells(1).Value serial = rowInspection.Cells(2).Value inspectionDate = rowInspection.Cells(3) For Each row in rng.rows If (row.Cells(1).Value = part And row.Cells(2).Value = serial) Then row.Cells(4).Value = inspectionDate EndIf Next row Next rowInspection