
Tenho 2 planilhas com colunas como comerciante, valor, dados, etc. O que é 100% comum entre as duas planilhas é o valor. Quero combinar/descobrir as linhas da planilha 1 + planilha 2 que contêm a mesma quantidade. Em uma das planilhas tenho mais dados do que na outra, então, por exemplo, a 3ª linha da planilha 1 não corresponde à 3ª linha da planilha 2. De alguma forma, tenho que pesquisar o valor.
Responder1
Isso deve bastar, mas sua pergunta não está clara :(
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
Existem falhas, como o que acontece se houver múltiplas ocorrências do valor, o que acontece se os dados da planilha1 tiverem valores maiores ou menores que os da planilha2, como a informação deve ser apresentada etc.
Independentemente disso, este VBa deve ajudá-lo, pois pode ser ajustado
Folha 1
Folha 2
Folha 3 (criada após a execução da macro)
Responder2
=VLOOKUP(B1,Sheet1!$A$1:$B$28,2,0)
encontra a primeira instância.
=COUNTIF(Sheet1!$A:$A,Sheet2!B2)
informa se há mais do que uma instância.