ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   removing hard breaks from comments or active cells (https://www.excelbanter.com/excel-programming/298293-removing-hard-breaks-comments-active-cells.html)

Julian[_2_]

removing hard breaks from comments or active cells
 
Dear All,
How do you remove hard breaks (returns) using a macro? I import files
& text with hard breaks causes problems as our system doesn't allow
such characters?

TIA
Julian

K Dales

removing hard breaks from comments or active cells
 
You can find and replace the hard breaks in any text by
looking for the corresponding character codes and removing
them - but I would need to know for sure how your input
text file was encoded. Most text files use the ASCII code
10 for a new line, but sometimes it is the code
combination of 13, 10. To see exactly which codes your
file uses, assign a small sample (including a line break)
from one of your text files to the String variable
txtInput and try this:

For i = 1 to Len(txtInput)

debug.print Mid(txtInput, i,1) & ":" & Asc(Mid
(txtInput,i,1))

Next i

This will list your sample text in the immediate window
with each character followed by its code, and should allow
you to find the line breaks and the exact codes used.

Now all you need to do is eliminate those codes from your
input string - if the line breaks use just the code 10,
your macro could include a function as simple as this:

Function RemoveBreaks(txtInput as String) as String

RemoveBreaks = Replace(txtInput,Chr(10),"")

End Function


If you wanted to, you could even replace the line breaks
with another character - the following will put a forward
slash wherever there was a line break:

RemoveBreaks = Replace(txtInput,Chr(10),"/")

K Dales

-----Original Message-----
Dear All,
How do you remove hard breaks (returns) using a macro? I

import files
& text with hard breaks causes problems as our system

doesn't allow
such characters?

TIA
Julian
.



All times are GMT +1. The time now is 08:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com