To use reGex, you could use this as Function, remember to enable Microsoft VBScript Regular Expression 5.5
Function RMV(iCell As Range) As Variant
Dim regEx As Object: Set regEx = CreateObject("VBScript.RegExp") 'If Error Set regEx = New regexp
Dim strPattern As String
Dim strInput As String
Dim strReplace As String
Dim strOutput As String
strPattern = "\[\]|\[.+?\]|$"
If strPattern <> "" Then
strInput = CStr(iCell.Value)
strReplace = ""
With regEx
.Global = True
.MultiLine = False
.IgnoreCase = False
.Pattern = strPattern
End With
If regEx.test(strInput) Then
RMV = regEx.Replace(strInput, strReplace)
Else
RMV = "Not matched"
End If
End If
End Function
Where the ReGex test uses the \[\]|\[.+?\]|$
expression. I am also new to Regex, so this expression can be optimized.