【问题标题】:Extracting lookup_value from VLOOKUP formula on MacOS在 MacOS 上从 VLOOKUP 公式中提取 lookup_value
【发布时间】:2017-09-06 20:55:11
【问题描述】:

在 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

【问题讨论】:

标签: vba macos excel


【解决方案1】:

我这里没有要测试的 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    • 2015-05-05
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    相关资源
    最近更新 更多