[英]Excel VBA returning “Compile error: Expected: expression”
我正在嘗試為另一個 function 的返回值設置一個值,但我被困在這條線上:
Set tempMergeValue = TypeRegxFunc(MyRange.Rows(iCounter).Columns(1).Value,'([^.]+)')
TypeRegxFunc 在這里
Function TypeRegxFunc(strInput As String, regexPattern As String) As String
Dim regEx As New RegExp
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = regexPattern
End With
If regEx.Test(strInput) Then
Set matches = regEx.Execute(strInput)
TypeRegxFunc = matches(0).Value
Else
TypeRegxFunc = "not matched"
End If
End Function
您必須將撇號''
替換為引號""
,否則 VBA 會將其解釋為注釋。
更改此行:
Set tempMergeValue = TypeRegxFunc(MyRange.Rows(iCounter).Columns(1).Value,'([^.]+)')
有了這個:
Set tempMergeValue = TypeRegxFunc(MyRange.Rows(iCounter).Columns(1).Value,"([^.]+)")
它會起作用。
我希望這有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.