Results 1 to 4 of 4

Type mismatch in arguments when I try to call a function

Threaded View

  1. #1
    Registered User
    Join Date
    12-27-2018
    Location
    Bogota, Colombia
    MS-Off Ver
    Excel 2013, 2016
    Posts
    25

    Type mismatch in arguments when I try to call a function

    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.
    Attached Files Attached Files
    Last edited by FZappa; 06-19-2019 at 04:30 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Function 'as long' gives type mismatch
    By truk2 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-17-2019, 10:34 PM
  2. Type mismatch on call to QueryTables.Add
    By mogilshik in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-11-2018, 03:19 PM
  3. [SOLVED] Type mismatch when using Match function
    By Unome in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-21-2017, 06:23 PM
  4. [SOLVED] Type mismatch using worksheet object arguments in procedure
    By perducci in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-21-2012, 01:35 PM
  5. Match Function Type Mismatch
    By officialhopsof in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 06-14-2011, 02:58 AM
  6. Type Mismatch - Match function
    By T De Villiers in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-31-2006, 10:48 AM
  7. Type mismatch in look up function
    By bisjom in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-09-2006, 01:16 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1