#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default Export text in ""

I want export (as a csv file) some data to create a TomTom POI file.
I have Latitude, Longitude, Name
I need to export the Name column in " " eg:
53.5,-0.8,"Name of location"
Rather than:
53.5,-0.8,Name of location

Any way to do this?
--
Regards, Dean
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default Export text in ""

Thought I'd worked this out but it didn't work :-(

Applied a custom number format to the column of \"@\"
This displays " " round the text but doesn't export them to the .csv file.
--
Regards, Dean


"Melbridge" wrote:

I want export (as a csv file) some data to create a TomTom POI file.
I have Latitude, Longitude, Name
I need to export the Name column in " " eg:
53.5,-0.8,"Name of location"
Rather than:
53.5,-0.8,Name of location

Any way to do this?
--
Regards, Dean

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default Export text in ""

Tried this again and it sort of works but it is exporting tripple " round the
text!
eg I want 004 to be exported as "004" but it is being exported as """004"""
Very confusing!
--
Regards, Dean


"Melbridge" wrote:

Thought I'd worked this out but it didn't work :-(

Applied a custom number format to the column of \"@\"
This displays " " round the text but doesn't export them to the .csv file.
--
Regards, Dean


"Melbridge" wrote:

I want export (as a csv file) some data to create a TomTom POI file.
I have Latitude, Longitude, Name
I need to export the Name column in " " eg:
53.5,-0.8,"Name of location"
Rather than:
53.5,-0.8,Name of location

Any way to do this?
--
Regards, Dean

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default Export text in ""

Found this code here http://www.mcgimpsey.com/excel/textfiles.html

Public Sub OutputQuotedCSV()
Const QSTR As String = """"
Dim myRecord As Range
Dim myField As Range
Dim nFileNum As Long
Dim sOut As String

nFileNum = FreeFile
Open "File1.txt" For Output As #nFileNum
For Each myRecord In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
With myRecord
For Each myField In Range(.Cells(1), _
Cells(.Row, 256).End(xlToLeft))
sOut = sOut & "," & QSTR & _
Replace(myField.Text, QSTR, QSTR & QSTR) & QSTR
Next myField
Print #nFileNum, Mid(sOut, 2)
sOut = Empty
End With
Next myRecord
Close #nFileNum
End Sub

However this exports all the data in quotes.
Can this be changed so it only exports column C in quotes and not columns A
and B
eg: 53.5,-0.8,"004"

--
Regards, Dean


"Melbridge" wrote:

Tried this again and it sort of works but it is exporting tripple " round the
text!
eg I want 004 to be exported as "004" but it is being exported as """004"""
Very confusing!
--
Regards, Dean


"Melbridge" wrote:

Thought I'd worked this out but it didn't work :-(

Applied a custom number format to the column of \"@\"
This displays " " round the text but doesn't export them to the .csv file.
--
Regards, Dean


"Melbridge" wrote:

I want export (as a csv file) some data to create a TomTom POI file.
I have Latitude, Longitude, Name
I need to export the Name column in " " eg:
53.5,-0.8,"Name of location"
Rather than:
53.5,-0.8,Name of location

Any way to do this?
--
Regards, Dean

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Export text in ""

JE's code makes sure that fields that contain double quotes are fixed.

It looks like you don't care if that's included. If that's true...

Option Explicit
Public Sub OutputQuotedCSV()
Const QSTR As String = """"
Dim myRecord As Range
Dim myField As Range
Dim nFileNum As Long
Dim sOut As String

nFileNum = FreeFile
Open "File1.txt" For Output As #nFileNum
For Each myRecord In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row).Cells
With myRecord
For Each myField In Range(.Cells(1), _
Cells(.Row, 256).End(xlToLeft))
If myField.Column = 3 Then
'include the quote:
sOut = sOut & "," & QSTR & myField.Text & QSTR
Else
'omit the quote
sOut = sOut & "," & myField.Text
End If
Next myField
Print #nFileNum, Mid(sOut, 2)
sOut = Empty
End With
Next myRecord
Close #nFileNum
End Sub



Melbridge wrote:

Found this code here http://www.mcgimpsey.com/excel/textfiles.html

Public Sub OutputQuotedCSV()
Const QSTR As String = """"
Dim myRecord As Range
Dim myField As Range
Dim nFileNum As Long
Dim sOut As String

nFileNum = FreeFile
Open "File1.txt" For Output As #nFileNum
For Each myRecord In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
With myRecord
For Each myField In Range(.Cells(1), _
Cells(.Row, 256).End(xlToLeft))
sOut = sOut & "," & QSTR & _
Replace(myField.Text, QSTR, QSTR & QSTR) & QSTR
Next myField
Print #nFileNum, Mid(sOut, 2)
sOut = Empty
End With
Next myRecord
Close #nFileNum
End Sub

However this exports all the data in quotes.
Can this be changed so it only exports column C in quotes and not columns A
and B
eg: 53.5,-0.8,"004"

--
Regards, Dean

"Melbridge" wrote:

Tried this again and it sort of works but it is exporting tripple " round the
text!
eg I want 004 to be exported as "004" but it is being exported as """004"""
Very confusing!
--
Regards, Dean


"Melbridge" wrote:

Thought I'd worked this out but it didn't work :-(

Applied a custom number format to the column of \"@\"
This displays " " round the text but doesn't export them to the .csv file.
--
Regards, Dean


"Melbridge" wrote:

I want export (as a csv file) some data to create a TomTom POI file.
I have Latitude, Longitude, Name
I need to export the Name column in " " eg:
53.5,-0.8,"Name of location"
Rather than:
53.5,-0.8,Name of location

Any way to do this?
--
Regards, Dean


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default Export text in ""

Thanks Dave, that works perfectly.
--
Regards, Dean


"Dave Peterson" wrote:

JE's code makes sure that fields that contain double quotes are fixed.

It looks like you don't care if that's included. If that's true...

Option Explicit
Public Sub OutputQuotedCSV()
Const QSTR As String = """"
Dim myRecord As Range
Dim myField As Range
Dim nFileNum As Long
Dim sOut As String

nFileNum = FreeFile
Open "File1.txt" For Output As #nFileNum
For Each myRecord In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row).Cells
With myRecord
For Each myField In Range(.Cells(1), _
Cells(.Row, 256).End(xlToLeft))
If myField.Column = 3 Then
'include the quote:
sOut = sOut & "," & QSTR & myField.Text & QSTR
Else
'omit the quote
sOut = sOut & "," & myField.Text
End If
Next myField
Print #nFileNum, Mid(sOut, 2)
sOut = Empty
End With
Next myRecord
Close #nFileNum
End Sub



Melbridge wrote:

Found this code here http://www.mcgimpsey.com/excel/textfiles.html

Public Sub OutputQuotedCSV()
Const QSTR As String = """"
Dim myRecord As Range
Dim myField As Range
Dim nFileNum As Long
Dim sOut As String

nFileNum = FreeFile
Open "File1.txt" For Output As #nFileNum
For Each myRecord In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
With myRecord
For Each myField In Range(.Cells(1), _
Cells(.Row, 256).End(xlToLeft))
sOut = sOut & "," & QSTR & _
Replace(myField.Text, QSTR, QSTR & QSTR) & QSTR
Next myField
Print #nFileNum, Mid(sOut, 2)
sOut = Empty
End With
Next myRecord
Close #nFileNum
End Sub

However this exports all the data in quotes.
Can this be changed so it only exports column C in quotes and not columns A
and B
eg: 53.5,-0.8,"004"

--
Regards, Dean

"Melbridge" wrote:

Tried this again and it sort of works but it is exporting tripple " round the
text!
eg I want 004 to be exported as "004" but it is being exported as """004"""
Very confusing!
--
Regards, Dean


"Melbridge" wrote:

Thought I'd worked this out but it didn't work :-(

Applied a custom number format to the column of \"@\"
This displays " " round the text but doesn't export them to the .csv file.
--
Regards, Dean


"Melbridge" wrote:

I want export (as a csv file) some data to create a TomTom POI file.
I have Latitude, Longitude, Name
I need to export the Name column in " " eg:
53.5,-0.8,"Name of location"
Rather than:
53.5,-0.8,Name of location

Any way to do this?
--
Regards, Dean


--

Dave Peterson
.

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
Text "comparison" operator for "contains" used in an "IF" Function Pawaso Excel Worksheet Functions 4 April 4th 23 11:35 AM
text string: "91E10" in csv file auto converts to: "9.10E+11" [email protected] Excel Discussion (Misc queries) 2 August 12th 08 03:13 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
how i convert "100" to "hundred"( number to text) in excel-2007 mohanraj Excel Worksheet Functions 1 May 11th 08 09:07 PM
Insert "-" in text "1234567890" to have a output like this"123-456-7890" Alwyn Excel Discussion (Misc queries) 3 October 25th 05 11:36 PM


All times are GMT +1. The time now is 04:00 PM.

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"