I use Excel 2007 and have created the function below to eliminate some characters from a string.
Public Function CleanString(sUser As String) As String
Dim lStringSize As Long, lCounter As Long
Dim iCode As Integer
Dim sChar As String
Application.Volatile
On Error GoTo ErrorHandler
lStringSize = Len(sUser)
For lCounter = 1 To lStringSize
sChar = Mid(sUser, lCounter, 1)
iCode = Asc(sChar)
If ((iCode < 65) Or (iCode > 90 And iCode < 97) Or (iCode > 122)) And (iCode <> 45) Then
sUser = Replace(sUser, sChar, Chr(32))
End If
Next lCounter
CleanString = sUser
Exit Function
ErrorHandler:
CleanString = ""
Exit Function
End Function
When I use this function as follows in my spreadsheet B1 contains the string "Samyn; Filiep" and the result in C1 = CleanString(B1) generates the expected result "Samyn Filiep" The problem is that after saving and reopening the worksheet C1 contains "Samyn; Filiep" i.e. the B1 without any function applied similar as if C1 would contain the formula = B1. I have tried application.calculate, application.calculatefull, and selection.calculate (where selection is C1) but the result does not update. The only way to have the results back is to edit C1 and after enter the result is correct. Nevertheless upon reopening the results are gone again. I have no other code besides the listed function. Excel is set for auto recalculation. My first question is why do the results of the executed function disappear when saving. My second question is why does the cell using the function not update when doing a full recalculation.