PDA

Click to See Complete Forum and Search --> : unwanted symbol


yanty
Apr 14th, 2006, 09:53 AM
I am currently exporting data to an excel worksheet.

One of the data consist an address field which when exported to excel, will be in a multi line order. eg.

vba building
22 new york street
new york 122655

but the problem is that beside name of building, address and postal code will appear a square symbol (i'm guessing its becos of the enter key which allows multiline data). tried to do the replace function to replace the square with a blank, but it didnt work, squares still visible.

anyone know how to make the square box dissapear?

DKenny
Apr 14th, 2006, 10:16 AM
You could use the excel CLEAN function, which will remove all non-printable character.

yanty
Apr 14th, 2006, 10:37 AM
could you give me an example where can i put the clean function?

DKenny
Apr 14th, 2006, 11:09 AM
Sub CleanExample()
Dim rngAreaToClean As Range
Dim rngMyCell As Range

'Whatever range you need to clean
Set rngAreaToClean = ThisWorkbook.Worksheets(1).UsedRange

'Loop through each cell
For Each rngMyCell In rngAreaToClean.Cells

With rngMyCell

'Removing non-prinable characters
.Value = Application.WorksheetFunction.Clean(.Value)

End With

Next rngMyCell
End Sub

cssriraman
Apr 14th, 2006, 01:04 PM
Hi Declan,

Thanks for this Great code!

But, I would like to know what the non-printable characters this code will remove?

DKenny
Apr 14th, 2006, 02:42 PM
I believe that it will remove all nonprintable characters,
LF, CR NBSP, etc

New2vba
Apr 16th, 2006, 04:34 PM
I also encounter the "squares" problem from time to time in Excel 2003 and thought this CLEAN function would be of real use. However, when I applied it, it also brought the second line of any cells containing multiline text back to the first :cry: .

For example, a table header (cell) with the title:

Total
Mass

was changed to:

TotalMass

cssriraman
May 7th, 2006, 12:15 AM
Yes! it happend to me also. How can we get around of this problem.

Is there any equivalent code in vb6? (not using excel)

RobDog888
May 7th, 2006, 02:26 AM
A carriage return or Enter key is a non-printable character. So when you use Clean it removes the line breaks and it will all appear on one line.