Problema con vlook up vba
Hola a todos !
Tengo el siguiente código:
Sub Resumen_Planillas_Individuales_TCT()
Dim tipo_combustible As String
Dim x As Integer
Dim celda As Object
Dim y As Integer
Dim rango As Range
Dim rango2 As Range
Dim sociedad As String
Dim nombre_archivo As String
Dim direccion_archivo As String
nombre_archivo = ActiveWorkbook.Name
direccion_archivo = ActiveWorkbook.FullName
'MsgBox direccion_archivo
Range("C:C").Select
Selection.Insert shift:=xlToRight, copyorigin:=xlFormatFromLeftOrAbove
Range("C1").Value = "Patente1"
Set rango = Range("B2:B" & WorksheetFunction.CountA(Range("A:A")))
For Each celda In rango.Cells
If UCase(Mid(celda.Value, 4, 1)) = "A" Or UCase(Mid(celda.Value, 4, 1)) = "B" Or UCase(Mid(celda.Value, 4, 1)) = "C" Or UCase(Mid(celda.Value, 4, 1)) = "D" Or UCase(Mid(celda.Value, 4, 1)) = "E" Or UCase(Mid(celda.Value, 4, 1)) = "F" _
Or UCase(Mid(celda.Value, 4, 1)) = "G" Or UCase(Mid(celda.Value, 4, 1)) = "H" Or UCase(Mid(celda.Value, 4, 1)) = "I" Or UCase(Mid(celda.Value, 4, 1)) = "J" Or UCase(Mid(celda.Value, 4, 1)) = "K" Or UCase(Mid(celda.Value, 4, 1)) = "L" _
Or UCase(Mid(celda.Value, 4, 1)) = "M" Or UCase(Mid(celda.Value, 4, 1)) = "N" Or UCase(Mid(celda.Value, 4, 1)) = "O" Or UCase(Mid(celda.Value, 4, 1)) = "P" Or UCase(Mid(celda.Value, 4, 1)) = "Q" Or UCase(Mid(celda.Value, 4, 1)) = "R" _
Or UCase(Mid(celda.Value, 4, 1)) = "S" Or UCase(Mid(celda.Value, 4, 1)) = "T" Or UCase(Mid(celda.Value, 4, 1)) = "U" Or UCase(Mid(celda.Value, 4, 1)) = "V" Or UCase(Mid(celda.Value, 4, 1)) = "W" Or UCase(Mid(celda.Value, 4, 1)) = "X" _
Or UCase(Mid(celda.Value, 4, 1)) = "Y" Or UCase(Mid(celda.Value, 4, 1)) = "Z" Then
Cells(celda.Row, "C").Value = CStr(Left(celda.Value, 2) & Right(celda.Value, 5))
Else
Cells(celda.Row, "C").Value = CStr(Left(celda.Value, 2) & "-" & Right(celda.Value, 4))
End If 'Cierra el if para transformar la patente
Next
Range("D:D").Select
Selection.Insert shift:=xlToRight, copyorigin:=xlFormanFromLeftOrAbove
Range("D1").Value = "Centro de Costo"
Range("D:D").Select
Selection.Insert shift:=xlToRight, copyorigin:=xlFormanFromLeftOrAbove
Range("D1").Value = "Gerencia Corporativa"
Range("D:D").Select
Selection.Insert shift:=xlToRight, copyorigin:=xlFormanFromLeftOrAbove
Range("D1").Value = "Sociedad"
x = WorksheetFunction.CountA(Range("A:A"))
Set rango = Range("C2:C" & x)
Workbooks.Open ("C:\Users\Usuario\Desktop\CONSUMOS\FLOTA RENTING - PROPIA OPERATIVA 04-02-2013.xlsx")
Workbooks("FLOTA RENTING - PROPIA OPERATIVA 04-02-2013.xlsx").Activate
Worksheets("Flota Renting").Select
y = WorksheetFunction.CountA(Range("A:A"))
Set rango2 = Workbooks("FLOTA RENTING - PROPIA OPERATIVA 04-02-2013.xlsx").Worksheets("Flota Renting").Range("A2:W" & y)
Workbooks(nombre_archivo).Activate
For Each celda In rango.Cells
If (Application.VLookup(celda, rango2, 5, False)) = False Then
Cells(celda.Row, "E") = Application.VLookup(celda, rango2, 5, False)
Else
Workbooks("FLOTA RENTING - PROPIA OPERATIVA 04-02-2013.xlsx").Activate
Worksheets("Flota Propia Operativa").Select
y = WorksheetFunction.CountA(Range("A:A"))
Set rango2 = Workbooks("FLOTA RENTING - PROPIA OPERATIVA 04-02-2013.xlsx").Worksheets("Flota Propia Operativa").Range("A2:Q" & y)
Workbooks(nombre_archivo).Activate
Cells(celda.Row, "E") = Application.VLookup(celda, rango2, 3, False)
End If
Next
End Sub
Al ejecutar la macro, algunos de los valores que busco en con el vlookup me aparece #N/A siendo que sí existen en la base de datos donde busco.
¿Por qué se puede generar ese problema?
De antemano, gracias por la ayuda !