Hi all. I wrote a function that I believe will be able to put out a value from a fairly complex table based on the values of three of its columns. This is said function
Function AlturaLookup(Rango As Range, Col As Integer, Especie As Variant, LugarAsignado As Variant, Fecha As Variant) As Long
'Busca en el formato original los valores de altura segun la especie y el lugar asignado
Dim Cell
Dim FilaCorriente As Integer
Dim NoDeFilas As Integer
Dim NoDeColumnas As Integer
Dim FilaEquivalente As Integer
AlturaLookup = CVErr(xlErrNA)
FilaEquivalente = 0
FilaCorriente = 1
NoDeFilas = Rango.Rows.Count
NoDeColumnas = Rango.Columns.Count
If Col > NoDeColumnas Then
AlturaLookup = CVErr(x1ErrNA)
End If
If Col <= NoDeColumnas Then
Do
If ((Rango.Cells(FilaCorriente, 2).Value = Especie) And _
(Rango.Cells(FilaCorriente, 8).Value = LugarAsignado) And _
(Rango.Cells(FilaCorriente, 1).Value = Fecha)) Then
FilaEquivalente = FilaCorriente
End If
FilaCorriente = FilaCorriente + 1
Loop Until ((FilaCorriente = NoDeFilas) Or (FilaEquivalente <> 0))
If FilaEquivalente <> 0 Then
AlturaLookup = Rango.Cells(FilaEquivalente, Col)
End If
End If
End Function
Now I think the function is likely to work, but since I'm standing on the shoulders of giants here, I'm working with a lot of stuff I've never used before, so to test it out I wrote the very simple call sub below:
Sub RunAlturaLookup()
Dim Altura As Long
Altura = AlturaLookup("A6:L34", "10", "Retrophyllum rospigliosii", "S.I.", "S.F")
Worksheet("NUEVO FORMATO CRECIMIENTO").Range("B3").Value = Altura
End Sub
The error I'm getting right of the bat is "Type mismatch" and the argument where the range goes is highlighted. I'd love it if someone could fix the problem, but more importantly, is this the correct way to call said function? I'm having a hard time figuring out based on the resources I've looked up.
I've attached a sample workbook if it helps.
Bookmarks