Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

To delete "hard" carrige returns in Excel

Thread Tools
 
Search this Thread
 
Old 10 June 2003, 12:35 PM
  #1  
Mick
Scooby Senior
Thread Starter
iTrader: (1)
 
Mick's Avatar
 
Join Date: Nov 1998
Posts: 2,655
Received 4 Likes on 2 Posts
Question

A mate has a spreadsheet that needs the hard carrige returns within the cells (put in by Alt + Enter to get lines within the cell) removing.

Instead of deleting the offending text withing each cell he is under the impression he was once shown how to do it with 'find and replace'. The problem is what is the code for the hard carrige return that needs to be replaced. He thinks it begins with a '~'

Cheers

Mick
Old 10 June 2003, 12:46 PM
  #2  
beemerboy
Scooby Regular
 
beemerboy's Avatar
 
Join Date: Sep 2002
Location: Essexville
Posts: 4,391
Likes: 0
Received 0 Likes on 0 Posts
Post

if you write a macro to do this, the alt and enter gives you this

& Chr(10)

not sure if this helps, i'm sure it prob doesnt.

BB
Old 10 June 2003, 01:02 PM
  #3  
4lex L
Scooby Regular
 
4lex L's Avatar
 
Join Date: Apr 2003
Posts: 110
Likes: 0
Received 0 Likes on 0 Posts
Post

I also believe the best way would be to use a macro. You used to be able to insert any ascii code in to text boxes by holding down alt and then typing the corrosponding code (e.g. 10) using the number keys on the keypad. I use a laptop so I don't have a keypad to test it with.

If your mate just wishes to replace the text he may want to try formatting the cells in a certain way and then use the find/repalce function to search for the specific format using a letter that always appears in the text as the search criteria.

Hope this helps if you were able to make any sense of that

Alex
Old 10 June 2003, 02:02 PM
  #4  
Mick
Scooby Senior
Thread Starter
iTrader: (1)
 
Mick's Avatar
 
Join Date: Nov 1998
Posts: 2,655
Received 4 Likes on 2 Posts
Post

Thanks guys...

All he wants to do is get rid of the carriage returns to get the text as a continuous line. - I'm not sure how your advice fits in...

Mick
Old 10 June 2003, 02:10 PM
  #5  
V5
Scooby Regular
 
V5's Avatar
 
Join Date: Jul 2002
Posts: 1,933
Likes: 0
Received 0 Likes on 0 Posts
Post

using the number keys on the keypad. I use a laptop so I don't have a keypad to test it with
You can usually do this - most laptops have the number keypad marked on the letters. You normally have to press and hold something like an "Fn" key, or similar.

Old 10 June 2003, 07:01 PM
  #6  
4lex L
Scooby Regular
 
4lex L's Avatar
 
Join Date: Apr 2003
Posts: 110
Likes: 0
Received 0 Likes on 0 Posts
Post

Your right, cheers V5 its been a long day , it didn't work anyway

The only way to remove the line breaks (I think) is programmatically using a macro. If I get a spare minute or two I'll write you a small function shouldn't take long.

Alex
Old 10 June 2003, 09:56 PM
  #7  
4lex L
Scooby Regular
 
4lex L's Avatar
 
Join Date: Apr 2003
Posts: 110
Likes: 0
Received 0 Likes on 0 Posts
Lightbulb

Ok try the following code, it will remove the carriage returns and replace them with spaces. It'll only work for the first carriage return and will not process subsequent occurrences in the same cell.

Public Function RemoveLine(area As Range)
Dim i, j
Dim str As String
Dim nPos As Integer

'loop through all cells in range
For i = 1 To area.Rows.Count
For j = 1 To area.Columns.Count
str = area(i, j).Value
'find position of the carriage return
nPos = InStr(1, str, Chr(10))
'if it exists replace it with a space
If nPos > 0 Then area(i, j).Value = Mid(str, 1, nPos - 1) & " " & Mid(str, nPos + 1, Len(str))
Next j
Next i
End Function

Private Sub CommandButton1_Click()
RemoveLine Worksheets("Sheet1").Range("A1:Z99")
End Sub
Old 11 June 2003, 10:01 AM
  #8  
Mick
Scooby Senior
Thread Starter
iTrader: (1)
 
Mick's Avatar
 
Join Date: Nov 1998
Posts: 2,655
Received 4 Likes on 2 Posts
Post

Thanks Alex - I'll give it a go...

Presumably it can be run through a couple of times to clear all line breaks????

Cheers

Mick
Old 11 June 2003, 10:22 AM
  #9  
4lex L
Scooby Regular
 
4lex L's Avatar
 
Join Date: Apr 2003
Posts: 110
Likes: 0
Received 0 Likes on 0 Posts
Post

Yeah that should work!
Old 11 June 2003, 04:21 PM
  #10  
4lex L
Scooby Regular
 
4lex L's Avatar
 
Join Date: Apr 2003
Posts: 110
Likes: 0
Received 0 Likes on 0 Posts
Post

Run the code several times over Jason It'll only filter the first carriage return it comes across. If you run the code over again the first carriage return will have already been converted to a space, so what was the second return now becomes the first and so will be filtered. If the cells contain a maximum of, say, 10 carriage returns then the following amendment to the command button click event handler should suffice:

Private Sub CommandButton1_Click()
Dim i as Integer
For i = 0 To 9
RemoveLine Worksheets("Sheet1").Range("A1:Z99")
Next i
End Sub
Old 11 June 2003, 06:22 PM
  #11  
4lex L
Scooby Regular
 
4lex L's Avatar
 
Join Date: Apr 2003
Posts: 110
Likes: 0
Received 0 Likes on 0 Posts
Post

Sorry Jason, couldn't get that to work

Old 11 June 2003, 06:52 PM
  #12  
4lex L
Scooby Regular
 
4lex L's Avatar
 
Join Date: Apr 2003
Posts: 110
Likes: 0
Received 0 Likes on 0 Posts
Post

Aah cell A1, I was trying elsewhere on the sheet

Edited to say it still only seem to remove the 1st carriage return so you get:

10 20
30

Nevermind Jason , better luck at the quiz tonight hey

[Edited by 4lex L - 6/11/2003 6:57:15 PM]

[Edited by 4lex L - 6/11/2003 6:57:45 PM]
Old 11 June 2003, 07:12 PM
  #13  
4lex L
Scooby Regular
 
4lex L's Avatar
 
Join Date: Apr 2003
Posts: 110
Likes: 0
Received 0 Likes on 0 Posts
Post

Alright smart ****
Old 27 June 2003, 09:28 AM
  #14  
Mick
Scooby Senior
Thread Starter
iTrader: (1)
 
Mick's Avatar
 
Join Date: Nov 1998
Posts: 2,655
Received 4 Likes on 2 Posts
Post

Jason

Excellent job, copied & pasted into Excel VB 'new module' and it works 'straight out of the box'. Very good - Gold star

Cheers

Mick
Old 27 June 2003, 12:05 PM
  #15  
Dario
Scooby Regular
 
Dario's Avatar
 
Join Date: Sep 1999
Posts: 240
Likes: 0
Received 0 Likes on 0 Posts
Post

Can any of the experts on here help me with a problem I'm having with Access database import into Excel

- I want the hard carriage returns that are in the access database to be in the excel cells - at the moment the text is one continious line in excel and it's drving me crazy.

Regards

Dario
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Pro-Line Motorsport
Car Parts For Sale
48
21 July 2017 09:50 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
28 December 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
18 November 2015 07:03 AM
blackieblob
ScoobyNet General
2
02 October 2015 05:34 PM
Ganz1983
Subaru
5
02 October 2015 09:22 AM



Quick Reply: To delete "hard" carrige returns in Excel



All times are GMT +1. The time now is 08:46 PM.