我有此函数,它返回一个范围:
Private Function getInvestorsCompanyRange()
Dim companyStart As range
Dim lastRow As range
If Len(Trim(investorsCompanyRange.value)) = 0 Then
getInvestorsCompanyRange = range("A1")
Else
Set lastRow = investorsCompanyRange.End(xlDown)
getInvestorsCompanyRange = range(investorsCompanyRange, lastRow)
End If
End Function
这个函数可以根据我在表单中的组合框从该范围中获取正确的值:
Private Sub cmbNoteName_Change()
Dim investorsRange As range
Set investorsRange = getInvestorsCompanyRange
lblNoteCompany.Caption = investorsNameRange.Rows.Offset(cmbNoteName.ListIndex).value
End Sub
我一直在获取对象。.我知道getInvestorsCompanyRange返回正确的范围,因为当我尝试将其分配给组合框列表时-它显示正确的值。
您Set
不习惯从函数中分配返回值:不带Set(并且因为您没有指定函数的返回类型),而是返回Range的值,而不是范围本身。
Private Function getInvestorsCompanyRange() As Range
Dim companyStart As range
Dim lastRow As range
If Len(Trim(investorsCompanyRange.value)) = 0 Then
Set getInvestorsCompanyRange = Range("A1")
Else
Set lastRow = investorsCompanyRange.End(xlDown)
Set getInvestorsCompanyRange = Range(investorsCompanyRange, lastRow)
End If
End Function
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句