Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search and Replace a Tilby "~" 1

Status
Not open for further replies.

ste4en

Technical User
Aug 1, 2001
69
I need to replace a "~" character in an Excel spreadsheet with a "-" I have thousands of instances. I can not use search and replace? How do i do this..

I seem to remember using a search for an ASCI character but cant seem to do that either.

thanks
 
The tilde is a special character when using search and replace. Its meaning is to take the next character literally. The primary purpose would be to allow you to change asterisks and question marks rather than have them treated as wild cards.

In this case you want to change the literal tilde with something else (the dash), so in the replace dialog, you would enter two tildes as the text to be replaced. I.e.,
[tt]
Find what: ~~
Replace with: -
[/tt]
 
Hi! Try this:
Code:
Public Sub ScrubText()
'*****VARIABLE DECLARATIONS*****
    Dim SearchString As String, ReplacementString As String, ReplacementAttempts As Integer


Range("A1").Select

'*****INITIALIZE VARIABLE*****
Selection.End(xlDown).Select
ReplacementAttempts = Selection.Row

'Loop and clean...
        For CleanString = 1 To ReplacementAttempts
            Cells(CleanString, 1).Select
            ReplacementString = Replace(ActiveCell.Value, "~", "-")
            ActiveCell.Value = ReplacementString
        Next CleanString
        
        
End Sub

Note: this assumes that all your data is in the A column. Attach this routine to a command button and you are all set.

Tom

Born once die twice; born twice die once.
 
Go with what Zathras gave you - it's about 10 times as fast and needs no code module nor button...
Tom

Born once die twice; born twice die once.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top