
판매자, 금액, 데이터 등과 같은 열이 있는 2개의 시트가 있습니다. 두 시트 사이에 100% 공통점은 금액입니다. 동일한 금액을 포함하는 시트 1 + 시트 2의 행을 일치/찾고 싶습니다. 시트 중 하나에 다른 시트보다 더 많은 데이터가 있습니다. 예를 들어 시트 1의 세 번째 행이 시트 2의 세 번째 행과 일치하지 않습니다. 어떻게든 금액을 검색해야 합니다.
답변1
이렇게 해야 하지만 귀하의 질문이 매우 불분명합니다.
Sub FindTheThings()
Dim resultRow As Integer
resultRow = 2
Dim currentRow As Integer
currentRow = 2
Worksheets("Sheet3").Range("A1").Value = "Sheet1 row"
Worksheets("Sheet3").Range("B1").Value = "Sheet2 row"
Do While (Worksheets("Sheet1").Range("B" & currentRow).Value <> "")
Dim amount As String
amount = Worksheets("Sheet1").Range("B" & currentRow).Value
Dim currentRowSheet2 As String
currentRowSheet2 = 2
Do While (Worksheets("Sheet2").Range("B" & currentRowSheet2).Value <> "")
Dim sheet2amount As String
sheet2amount = Worksheets("Sheet2").Range("B" & currentRowSheet2).Value
If (sheet2amount = amount) Then
Worksheets("Sheet3").Range("A" & resultRow).Value = currentRow
Worksheets("Sheet3").Range("B" & resultRow).Value = currentRowSheet2
resultRow = resultRow + 1
Exit Do
End If
currentRowSheet2 = currentRowSheet2 + 1
Loop
currentRow = currentRow + 1
Loop
End Sub
금액이 여러 번 발생하면 어떻게 되는지, 시트1 데이터가 시트2보다 더 많거나 적은 값을 가지면 어떻게 되는지, 정보가 어떻게 표시되는지 등 결함이 있습니다.
그럼에도 불구하고 이 VBa는 조정할 수 있으므로 계속 진행할 수 있어야 합니다.
시트 1
시트 2
시트 3(매크로 실행 후 생성됨)
답변2
=VLOOKUP(B1,Sheet1!$A$1:$B$28,2,0)
첫 번째 인스턴스를 찾습니다.
=COUNTIF(Sheet1!$A:$A,Sheet2!B2)
인스턴스보다 더 많은 것이 있는지 알려줍니다.