Search code examples
excelcell

EXCEL: Cell.Value returning preceding "?"


I'm returning a cell value in part of my code, and then cleaning the data to remove illegal filename characters. One of these characters is of course the "?" and for some reason, some of my cells are returning the contents with a preceding ? despite this not being part of the cell.

Furthermore, the code I'm using to clean the string is not replacing this leading ? with a whitespace as I'd hoped it did.

Function Clean(ByVal sFolderName As String) As String

Dim i As Long
Dim sTemp As String

For i = 1 To Len(sFolderName)
      Select Case Mid$(sFolderName, i, 1)
         Case "/", "", ":", "*", "?", "<", ">", "|"
             sTemp = sTemp & ""
         Case Else
             sTemp = sTemp & Mid$(sFolderName, i, 1)
     End Select
 Next i

Clean = sTemp

End Function

For example, the value in a cell would show as 8324297444, but when trying to retrieve the cell.value property it returns ?8324297444. Then, when the clean-up function is called, it will keep this leading ? character.

I'm tearing my hair out trying to figure out what's going on here.

Anyone have any ideas?


Solution

  • After troubleshooting this for days, it appears to be an isolated incident which cannot be corrected. I have exhaused all possible suggestions provided on SO and other sources around the net.

    I was able to rectify the situation by identifying the data that was affected by this behaviour and re-keying it manually.

    It was not the most efficient solution, but it did solve the problem.

    If you encounter this problem, please be advised that this is the only fix I was able to find.