The problem is in the function TrueTrim. It modifies the input argument, which is a poor coding practice for a function. In VBA, the default argument mode is ByRef, so the modified argument is updated in the caller. The function should really use a local variable to do this, but the easiest fix is to explicitly use ByVal.
Public Function TrueTrim(ByVal str1 As Variant) As String
Dim i As Integer
' Problem is here
str1 = WorksheetFunction.Trim(Replace(str1, Chr(160), Chr(32))) 'per far funzionare Trim in modo corretto eliminando tutti i tipo di "spazi"
Bookmarks