我正在創建幾個用戶定義函數(UDF's)。我不夠熟練,我可以對我自己寫最代碼。但是,在某些情況下,我有興趣瞭解Microsoft如何處理輸入,防範錯誤並優化性能。 有誰知道在哪裏可以找到Microsoft用於編寫標準Excel公式的確切Visual Basic語法?是否有可能爲他們的標準Excel公式查看Microsoft VBA代碼?
爲了說明,下面是我創建模仿VLOOKUP一個UDF,我想它比微軟的功能。例如,微軟的代碼如何分析第一列?它使用單元格循環還是Match函數?它如何處理錯誤?
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
再說一遍,我不是在尋找答案VLOOKUP具體而言,我只是想看看微軟的方法來處理我面臨着各種各樣的我UDF的類似的公式挑戰。
我在Excel的VBA對象瀏覽器(2013年)檢查,我看到了下面的截圖,這是不是非常有幫助。當我查看我的Excel安裝文件夾時,找不到與工作表命名結構相對應的任何內容。
我想這可能是故意MS不希望共享這些信息,這將是令人失望的,但如果有人是肯定我會很感激的確認。
謝謝。
AFAIK Vba資源由Microsoft保留專有權,並且不公開提供 – Steve
'Excel.WorksheetFunction.VLookup'不是用VBA編寫的。它會寫成類似於C++的東西。正如Excel自身公式所使用的VLOOKUP功能一樣。 – YowE3K
拍攝感謝您的反饋,我標記爲有幫助。我認爲是這種情況,但我認爲這可能很容易解決像工作表或VBA保護。也許有人知道一種方式,所以我會繼續質疑一段時間。 – PGCodeRider