
Tengo 2 hojas con columnas como comerciante, monto, datos, etc. Lo 100% común entre las dos hojas es el monto. Quiero unir/descubrir las filas de la hoja 1 + hoja 2 que contienen la misma cantidad. En una de las hojas tengo más datos que en la otra, por lo que, por ejemplo, la tercera fila de la hoja 1 no coincide con la tercera fila de la hoja 2. De alguna manera tengo que buscar la cantidad.
Respuesta1
Esto debería bastar, pero tu pregunta no está muy 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
Hay fallas, como qué sucede si hay múltiples apariciones del monto, qué sucede si los datos de la hoja 1 tienen más o menos valores que la hoja 2, cómo se debe presentar la información, etc.
Independientemente, este VBa debería ayudarlo a continuar, ya que se puede modificar
Hoja 1
Hoja 2
Hoja 3 (creada después de la ejecución de la macro)
Respuesta2
=VLOOKUP(B1,Sheet1!$A$1:$B$28,2,0)
encuentra la primera instancia.
=COUNTIF(Sheet1!$A:$A,Sheet2!B2)
indica si hay más que en una instancia.