Dear all,
The vba code that I attached below returns "Not found" . I have checked the code that is inside the buttom several times but with no results.
martes.xlsm has to take the values in column C (Facturacion) from the excel file martes.xlsx . But the taken value must match with the column A (period) and column B(cod). Take note that the values in column A and B are repeated.
I have also tried Vlookup but It seems that Vlookup only can match with one column but no with two.
Please, someone could help me on this?
Regards,
>>> use code - tags <<<
The vba code that I attached below returns "Not found" . I have checked the code that is inside the buttom several times but with no results.
martes.xlsm has to take the values in column C (Facturacion) from the excel file martes.xlsx . But the taken value must match with the column A (period) and column B(cod). Take note that the values in column A and B are repeated.
I have also tried Vlookup but It seems that Vlookup only can match with one column but no with two.
Please, someone could help me on this?
Regards,
>>> use code - tags <<<
Code:
Sub indexmatch()
Dim wbLibroOrigen As Workbook
Dim wsHojaOrigen As Worksheet
Dim wbLibroDestino As Workbook
Dim wsHojaDestino As Worksheet
Dim lookup_value As String
Dim lookup_range As Range
Dim match_range As Range
Dim result As Variant
Dim Ruta As String
Ruta = "C:\martes.xlsx"
Dim i As Integer
'Datos Destino
Set wbLibroDestino = Workbooks(ThisWorkbook.Name)
Set wsHojaDestino = wbLibroDestino.Worksheets("Sheet1")
'Datos Origen
Set wbLibroOrigen = Workbooks.Open(Ruta)
Set wsHojaOrigen = wbLibroOrigen.Worksheets("Sheet1")
lookup_value = wsHojaDestino.Range("B2").Value & wsHojaDestino.Range("A2").Value
Set lookup_range = wsHojaOrigen.Range("B2:B7")
Set match_range = wsHojaOrigen.Range("A2:A7")
On Error Resume Next
result = Application.WorksheetFunction.Index(wsHojaOrigen.Range("C2:C7"), Application.WorksheetFunction.Match(lookup_value, Union(lookup_range, match_range), 0), 0)
If Err.Number <> 0 Then
result = "Not found"
Err.Clear
End If
On Error GoTo 0
wsHojaDestino.Range("C2").Value = result
End Sub
Attachments
-
20.6 KB Views: 2
-
11.2 KB Views: 2
Last edited by a moderator: