在MacOS上从VLOOKUP公式中提取lookup_value
在Windows上,我使用以下函数从VLOOKUP
公式中提取lookup_value
。 但是,我最近切换到macOS和function现在不兼容。
Mac上的Excel中的VBA不支持正则expression式。 有没有其他function可以使用,还是我运气不好?
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在这里testing,但我认为这应该工作:
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