代码之家  ›  专栏  ›  技术社区  ›  pgSystemTester

是否可以查看其标准Excel公式的Microsoft VBA代码?

  •  0
  • pgSystemTester  · 技术社区  · 8 年前

    我正在创建几个用户定义函数(UDF)。我很精通写作 我自己的代码。然而,在某些情况下,我有兴趣了解Microsoft如何处理输入、防范错误和优化性能。 有谁知道我在哪里可以找到Microsoft用来编写标准Excel公式的Visual Basic语法?

    Public Function VLookupPGCodeRider(TextInput As String, SearchRange As Range, _
    ColumnIndex As Integer, PartialMatch As Boolean) As String
    Dim WS As Worksheet, Rcell As Range
    Set WS = Sheets(SearchRange.Parent.Name)
    
    On Error GoTo BadResult
    If TextInput = "" Or SearchRange Is Nothing Or Not (IsNumeric(ColumnIndex)) Then
    GoTo BadResult
    End If
    On Error GoTo 0
    
    'I would like to see how MS sets up this loop, or maybe they use match?
    'But then how does match work??
    For Each Rcell In Intersect(SearchRange.Columns(1), WS.UsedRange).Cells
    
        If Not (PartialMatch) Then 'how 99.9% of users use Vlookup
            If Rcell.Value = TextInput Then
                VLookupPGCodeRider = Intersect(Rcell.EntireRow, SearchRange.Columns(ColumnIndex)).Value
                Exit Function
            End If
    
        Else
            'what is considered a partial match??
        End If
    
    Next Rcell
    
    'if nothing found or error in the beginning of formula...
    BadResult:
    VLookupPGCodeRider = "#NA"
    
    End Function
    

    我已经查看了Excel VBA对象浏览器(2013),我看到了下面的屏幕截图,这不是很有帮助。当我查看Excel安装文件夹时,没有找到任何与工作表函数的命名结构对应的内容。

    我想MS可能故意不想分享这些信息,这将令人失望,但如果有人能确定,我将不胜感激。

    非常感谢。

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  6
  •   YowE3K    8 年前

    的代码 Excel.WorksheetFunction.VLookup 等,不是用VBA编写的。它可以用C++之类的语言编写。正如 VLOOKUP Excel中公式本身使用的功能是。

    推荐文章