【问题标题】:Passing an argument to a function error type 13将参数传递给函数错误类型 13
【发布时间】:2019-04-10 22:39:41
【问题描述】:

我目前收到 13 类错误,因为函数似乎收到了错误的参数。我做错了什么?

Sheet 1 函数(当子调用此函数时,它会生成类型 13 错误):

Function extrapolatendg(row As Range) As Integer

extrapolatendg = Range("b" & row).Value

End Function

表 6 功能:

Function findrownumberndg(extrapolatendg As Integer)

Set foundcell = Range("a:a").Find(extrapolatendg, lookat:=xlWhole)

If Not foundcell Is Nothing Then

findrownumberndg = 0

Else

findrownumberndg = foundcell.row

End If

End Function

thisworkbook 子操作函数

Sub getndg()

For x = 6 To sheet1lastrow()

Dim currentRow As Range
Set currentRow = Sheet1.Rows(x)

extraolatendg = Sheet1.extrapolatendg(currentRow)

Sheet6.findrownumberndg (extrapolatendg)

Next

End Sub

我希望 extrapolatendg 函数获取单元格值并将其传递给 findrownumberndg 以便在另一张表中返回行号。

【问题讨论】:

  • 我怀疑你的函数有一个工作表父级:Sheet1.extrapolatendg(currentRow) 应该只是 extrapolatendg(currentRow)
  • 如果rowRange,则不能使用Range("b" & row)
  • 如果值不是IntegerFunction extrapolatendg(row As Range) As Integer 也会抛出错误。

标签: excel vba function arguments


【解决方案1】:

我不认为这个函数能像你想象的那样做。这就是它正在做的事情

Function extrapolatendg(row As Range) As Integer
    'This is a function, it will do a calculation and return a value.
    ' It's name is extrapolatendg, 
     '(it accepts a range object (either a single cell or a block of cells) and calls that range "row") 
     'It will return an Integer value

     extrapolatendg = Range("b" & row).Value
     'since the object called row is being used in a context that expects a value, 
      'VBA will use the default property of the object - in this case the Value property
     'Find the Value property of the range called row 
     'if row is a single cell and has something in it that can be interpreted as a long then 
    'continue, otherwise throw an error of  "Type Mismatch".
    'Concatenate that long with the letter "b"
    'Pass that string as an argument to the function "Range" - 
    'This will return an object of type "Range"
    'Obtain the value of the "value" property of this object
    'Attempt to coerce this value into an Integer 
    '- if this succeeds, return this value as the result of the function extrapolatendg, 
    'otherwise throw an error "Type Mismatch"

 End Function  'finished

请注意,为了使用它,您必须传递它所期望的范围参数,所以

        Function findrownumberndg(extrapolatendg(Some cell reference goes here) As Integer)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多