在VBA中返回,没有达到我的期望 [英] Return in VBA, does not do what I expect
本文介绍了在VBA中返回,没有达到我的期望的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Public Function GetRowToWriteOn(ByVal SheetName As String, ByVal id As Integer) As Integer
LastRow = ActiveSheet.UsedRange.Rows.Count
myarray = Sheets(SheetName).Range("d7:d" & LastRow).Value
For row = 1 To UBound(myarray, 1)
If (myarray(row, 1) = id) Then
Return row
End If
Next
End Function
IDE表示预期的声明结尾,我该怎么做?(返回id相同的行吗?)
The IDE says expected end of statement, how do I do what I want? (Return the row where id is the same?)
我对VBA一点都不熟悉,但是当我从Microsoft看这个示例时,它应该可以工作吗?:
I'm not familiar at all with VBA, but when I look this example from microsoft this should work? :
Return语句同时分配返回值并退出该函数.以下示例显示了这一点.
The Return statement simultaneously assigns the return value and exits the function. The following example shows this.
Function myFunction(ByVal j As Integer) As Double
Return 3.87 * j
End Function
推荐答案
在VBA中,不通过return关键字返回值,因为在其他语言中这是自定义的.试试:
In VBA, returning a value is not done through the return keyword as it is custom in other languages. Try:
GetRowToWriteOn = row
函数名称自己充当变量.
The function name acts as a variable on its own.
这篇关于在VBA中返回,没有达到我的期望的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文