Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Replacing Carriage Returns

Hi,
I have a spreadsheet that is populated with Name and
Address data from a SQL Server database using MS Query.
Unfortunately the database stores the address in one
column, with the different parts (ie street, town/suburb)
seperated with Carriage Returns. Is there any way I can
replace this with a characted such as % or | (I know how I
can seperate it into different columns if I can replace it
with a unique character)

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default Replacing Carriage Returns

anonymous poster David,

09 TAB
10 LF (line feed) hex 0A
13 CR (carriage return) hex 0D

You can replace CR with TAB and then you will be set
using the default delimiter in Text to Columns

in VBA
expression.Replace(What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte)
-- usually written something like---

Selection.Replace What:=CHR(13), Replacement:=CHR(09)

if you want another character you can use Replacement:="%"

Since you are using VBA it might make more sense to simply
do everything in VBA

Sub SepColumnOnLF()
'-- if you have multiple LF in cells insert more columns and loop the LF
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'-- insert column to right of active cell, before separations
Dim cell As Range, i As Long
ActiveCell.Offset(0, 1).EntireColumn.Insert
For Each cell In Intersect(ActiveCell.EntireColumn, _
Selection.SpecialCells(xlConstants, xlTextValues))
i = InStr(1, cell.Value, Chr(10))
If i < 0 Then
cell.Offset(0, 1).Value = Mid(cell.Value, i + 1)
cell.Value = Left(cell.Value, i - 1)
End If
Next cell
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub


In Excel
Make selection
Ctrl+H
from: alt+0013 alt+0010 (two characters) on the numeric keypad, or
from alt+0010 (one character) on the numeric keypad
to: alt+0009 on the numeric keypad

You may have CRLF, CR, or LF depending on software, I don't know which you
will have. Excel generates a LF when you use Alt+Enter for instance.

May be of interest:
Creating a Spreadsheet from Database data (#dbdata)
http://www.mvps.org/dmcritchie/excel...col.htm#dbdata
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"David" wrote in message ...
Hi,
I have a spreadsheet that is populated with Name and
Address data from a SQL Server database using MS Query.
Unfortunately the database stores the address in one
column, with the different parts (ie street, town/suburb)
seperated [separated] with Carriage Returns. Is there any way I can
replace this with a characted such as % or | (I know how I
can seperate [separate] it into different columns if I can replace it
with a unique character)

Thanks



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing carriage returns with a comma Sue Compelling Excel Discussion (Misc queries) 5 April 22nd 10 09:00 AM
Carriage returns - how to get rid of them (again) Andrewsan Excel Discussion (Misc queries) 8 March 28th 07 10:15 AM
Delete Carriage Returns Andre Excel Discussion (Misc queries) 2 December 1st 05 09:50 PM
Replacing commas with carriage return Hardip Excel Worksheet Functions 4 September 1st 05 01:39 PM
Carriage returns tracyt620 Excel Discussion (Misc queries) 1 July 7th 05 02:52 PM


All times are GMT +1. The time now is 12:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"