【发布时间】:2023-03-29 22:38:02
【问题描述】:
如果这两个工作表中的某些值之间存在匹配,我正在研究如何合并工作簿中两个不同工作表中的文本。
我有两张表,Latency 和 DRG。我想将“DRG” Col E 中的文本合并到“延迟”表 Col P 中(行可能已经有文本,但“DRG” Col E 中的文本应该用分号合并。)
示例:(下面的代码进行匹配并更新 COl O 中的某个文本,我想将合并部分与此代码一起添加) 如果 "latency" 的 col A 和 "DRG" 的 Col B 匹配,则 "DRG" 的 Col E 中的文本应合并到 "Latency" 表的 Col P(该特定行)中。
欢迎任何更好的方法。
Sub PassFailValidation()
Dim Rng As Range, cl As Range
Dim LastRow As Long, MatchRow As Variant
With Sheets("DRG")
LastRow = .Cells(.Rows.count, "C").End(xlUp).Row '<-- find last row with data in column C
Set Rng = .Range("C2:C" & LastRow) '<-- set range in Column C
End With
With Sheets("Latency")
For Each cl In .Range("B2:B" & .Cells(.Rows.count, "B").End(xlUp).Row) ' loop through all cells in Column B
MatchRow = Application.Match(cl.Value, Rng, 0) ' find match with values in Colummn C as in "DRG" sheet
If Not IsError(MatchRow) Then ' <-- successful match
Select Case Sheets("DRG").Range("D" & MatchRow + 1).Value 'Set D as the cell whch has the value
Case "Approved"
.Range("O" & cl.Row).Value = "Pass"
Case "Pended"
.Range("O" & cl.Row).Value = "Fail"
Case "In progress"
.Range("O" & cl.Row).Value = "In progress"
End Select
End If
Next cl
End With
结束子
【问题讨论】:
-
你有一些测试数据吗?
-
如果需要,我可以创建一个并将其上传到任何第三方网站。