austin350s10
Active Member
- Joined
- Jul 30, 2010
- Messages
- 321
I am trying to use the following script to search through a cells text and replace any invalid characters with "_". This script will identify the invalid characters but it will not replace the text. What am I doing wrong here?
Code:
Sub test()
Dim i As Integer
Dim Pos As Integer
Dim SearchString As String
Dim correction As String
SearchString = Range("A1").Value
FindChar = Array(":", "/", " ")
For Each c In FindChar
For i = 1 To Len(SearchString)
If Mid(SearchString, i, 1) = c Then
Pos = i
correction = Replace(SearchString, i, "_")
Range("A1").Value = correction
End If
Next i
If Pos <> 0 Then
MsgBox Chr(34) & c & Chr(34) & " was Found at position " & Pos
End If
Pos = 0
Next c
End Sub