ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do you programically remove carriage returns within a cell (https://www.excelbanter.com/excel-programming/335045-how-do-you-programically-remove-carriage-returns-within-cell.html)

lee

How do you programically remove carriage returns within a cell
 
I need to do more than one cell at a time.

ben

How do you programically remove carriage returns within a cell
 
lee type your question the body of the text please.

sub removecarret()
dim cel as range
for each cel in activesheet.usedrange
cel = replace(cel,chr(13),"")
next
end sub
UNTESTED but it should work

--
When you lose your mind, you free your life.


"Lee" wrote:

I need to do more than one cell at a time.


Dave Peterson

How do you programically remove carriage returns within a cell
 
Saved from a previous post to a more generic question:

You can use Chip Pearson's Cell View addin to find out the character it is:
http://www.cpearson.com/excel/CellView.htm

If those box characters are char(10)'s (alt-enters), you can use
edit|Replace
what: ctrl-j
with: (spacebar??)
replace all

If that box character is something else, you may need a macro:

Option Explicit
Sub cleanEmUp()

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

myBadChars = Array(Chr(13)) '<--What showed up in CellView?

myGoodChars = Array(" ")

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

Lee wrote:

I need to do more than one cell at a time.


--

Dave Peterson


All times are GMT +1. The time now is 12:05 PM.

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