Решая только вопрос о том, как включить вашу функцию ...
Непроверенные:
Option Explicit
Public Sub RemoveEndWhiteSpace()
Dim arr(), i As Long, myRange As Range
Set myRange = Application.Intersect(Selection, ActiveSheet.UsedRange)
If myRange Is Nothing Then Exit Sub
If myRange.Columns.Count > 1 Then Exit Sub
If myRange.Count = 1 Then
myRange.Offset(0,1).Value = simpleCellRegex(myRange.Value)
Else
arr = myRange.Value
For i = LBound(arr, 1) To UBound(arr, 1)
arr(i, 1) = simpleCellRegex(arr(i, 1))
Next i
myRange.Offset(0, 1).Value = arr
End If
End Sub
Function simpleCellRegex(v) As String
Static Regex As RegExp
'need to create/configure regex?
If Regex Is Nothing Then
Set Regex = New Regex
With Regex
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = "s+$"
End With
End If
If Regex.Test(strInput) Then
simpleCellRegex = Regex.Replace(v, "")
Else
simpleCellRegex = v
End If
End Function