Replacing ascii characters

G

Guest

I have imported information from Access where one of the fields contains
manual line breaks. It appears Excel converts the manual line break into a
square box. I would like to do a find and replace on these square boxes but
am having a hard time figuring out what code to use. I am thinking the ascii
code is either 10 or 13 for the mlb. So for the find field what would you
type? I have tried CHAR(10) and CHAR(13) but when it searches it says it
can't find the data I am searching for. I know I was able to accomplish this
a year or so ago but have since forgotten how to do it. Anyone have a
suggestion?

In general, if you are searching for symbols within an Excel file, how do
you indicate the ascii code in the "find what" field?
 
D

Dave Peterson

Chip Pearson has a very nice addin that will help determine what that
character(s) is:
http://www.cpearson.com/excel/CellView.htm

Since you do see a box, then you can either fix it via a helper cell or a macro:

=substitute(a1,char(13),"")
or
=substitute(a1,char(13)," ")

Replace 13 with the ASCII value you see in Chip's addin.

Or you could use a macro (after using Chip's CellView addin):

Option Explicit
Sub cleanEmUp()

Dim myBadChars As Variant
Dim myGoodChars As Variant
Dim iCtr As Long

myBadChars = Array(Chr(9), Chr(160)) '<--What showed up in CellView?

myGoodChars = Array(" "," ") '<--what's the new character?

If UBound(myGoodChars) <> UBound(myBadChars) Then
MsgBox "Design error!"
Exit Sub
End If

For iCtr = LBound(myBadChars) To UBound(myBadChars)
ActiveSheet.Cells.Replace What:=myBadChars(iCtr), _
Replacement:=myGoodChars(iCtr), _
LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False
Next iCtr

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
 
B

Bernie Deitrick

HappyC,

Select the cells, then try this little macro, which will replace characters 10 and
13 with spaces.

HTH,
Bernie
MS Excel MVP


Sub ReplaceReturns()
Selection.Replace Chr(10), " ", xlPart
Selection.Replace Chr(13), " ", xlPart
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top