통합 문서에서 두 시트의 특정 값이 일치하는 경우 두 개의 다른 시트의 텍스트를 병합하는 방법을 알아 보겠습니다.두 개의 다른 시트의 텍스트 병합
지연 및 DRG 두 장이 있습니다. "DRG"Col E의 텍스트를 "지연 시간"시트 Col P로 병합하려고합니다 (행에 텍스트가 이미있을 수 있지만 "DRG"Col E의 텍스트는 세미콜론과 병합해야합니다).
예 : 아래의 코드는 일치 작업을 수행하고 COL O의 특정 텍스트를 업데이트합니다.이 코드와 함께 병합 부분을 추가하려고합니다. "대기 시간"의 col A와 "DRG"의 Col B가 일치하는 경우 텍스트 "DRG"의 Col E는 "대기 시간"시트의 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
최종 하위
다음
로? –
필요할 경우 제 3 자 사이트를 만들고 업로드 할 수 있습니다. –