我当前遇到类型13错误,因为函数似乎收到了错误的参数。我在做什么错了?
Sheet 1函数(当子调用此函数时,它会产生13型错误):
Function extrapolatendg(row As Range) As Integer
extrapolatendg = Range("b" & row).Value
End Function
Sheet 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
此工作簿子操作功能
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以便在另一张纸中返回行号。
答案 0 :(得分:0)
我认为此功能无法实现您认为的功能。这就是它的作用
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
请注意,要使用它,必须传递期望的range参数,因此
Function findrownumberndg(extrapolatendg(Some cell reference goes here) As Integer)