簡體   English   中英

在MacOS上從VLOOKUP公式中提取lookup_value

[英]Extracting lookup_value from VLOOKUP formula on MacOS

在Windows上,我使用以下函數從VLOOKUP公式中提取lookup_value 但是,我最近切換到了macOS,該功能現在不兼容。

Mac上的Excel中的VBA不支持正則表達式。 我可以使用其他功能嗎?還是我不走運?

Function extractFirstInt(strValue As String) As Integer
    Dim regex As New regexp
    regex.Pattern = "(\d+)"
    extractFirstInt = regex.Execute(strValue)(0).SubMatches(0)
End Function

我沒有要測試的Mac,但是我認為這應該可行:

Function extractFirstInt(strValue As String) As Integer
    Dim codes() As Byte
    Dim n As Long
    Dim pos As Long
    Dim length As Long
    If strValue Like "*#*" Then
        codes = strValue
        length = 1
        For n = LBound(codes) To UBound(codes) Step 2
            Select Case codes(n)
                Case 48 To 57
                    If pos = 0 Then pos = n \ 2 + 1 Else length = length + 1
                Case Else
                    If pos <> 0 Then Exit For
            End Select
        Next
        extractFirstInt = CInt(Mid$(strValue, pos, length))
    End If
End Function

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM