Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default CSV File format problem

Your problem seems similar to the one discussed he

http://support.microsoft.com/default...95&Product=xlw

You might have to use a macro to get the result you want. Try this one:

'Puts no quotes around strings
''Outputs the selection if more than one cell is selected, else entire sheet
''Include commas for missing items at end of row.
Sub OutputActiveSheetAsTrueCSVFileAllCommas()
Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim ListSep As String
Dim FName As Variant
Dim ColCount As Integer
Dim CurrCol As Integer
FName = Application.GetSaveAsFilename("", "CSV File (*.csv), *.csv")
If FName < False Then
ListSep = Application.International(xlListSeparator)
If Selection.Cells.Count 1 Then
Set SrcRg = Selection
Else
Set SrcRg = ActiveSheet.UsedRange
End If
ColCount = SrcRg.Columns.Count
Open FName For Output As #1
For Each CurrRow In SrcRg.Rows
CurrCol = 0
CurrTextStr = ""
For Each CurrCell In CurrRow.Cells
CurrCol = CurrCol + 1
CurrTextStr = CurrTextStr & CurrCell.Value & IIf(CurrCol <
ColCount, ListSep, "")
Next
Print #1, CurrTextStr
Next
Close #1
End If
End Sub


--
Jim Rech
Excel MVP
"Jac Tremblay" wrote in message
...
| Hi everyone,
|
| I get a problem with a worksheet when I export the data in a csv file. I
have a worksheet with 10 rows and 10 columns of data (100 cells). Not all of
them are filled. The last cell is J10.
| If I export this worksheet to a csv file, I get 9 commas separating the
data on each of the 10 lines. That's fine.
| If I add data in the range D11:D15, and reexport the worksheet to a csv
file, I get 10 lines with 9 commas and 5 lines with 3 commas. That's not
what I want. And that's not normal.
|
| If I use a new worksheet to test my problem, I get 15 lines with 9 commas
which is correct.
|
| What is (or may be) wrong with the first workbook?
|
| Thanks for your help.
| --
| Jac Tremblay


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default CSV File format problem

Hi Jim,
This macro does work well and I thank you for your help. But I still want to understand why one should have to use such a macro when Excel is supposed to do that job automatically.
Is it possible that some cell have a text format while the others below do not? Because, when I copy that last cell down to the last row, the problem does not appear and Excel treats these cells as if they had something in them.
I guess I will have to live with it...
Thank you again.

"Jim Rech" wrote:

Your problem seems similar to the one discussed he

http://support.microsoft.com/default...95&Product=xlw

You might have to use a macro to get the result you want. Try this one:

'Puts no quotes around strings
''Outputs the selection if more than one cell is selected, else entire sheet
''Include commas for missing items at end of row.
Sub OutputActiveSheetAsTrueCSVFileAllCommas()
Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim ListSep As String
Dim FName As Variant
Dim ColCount As Integer
Dim CurrCol As Integer
FName = Application.GetSaveAsFilename("", "CSV File (*.csv), *.csv")
If FName < False Then
ListSep = Application.International(xlListSeparator)
If Selection.Cells.Count 1 Then
Set SrcRg = Selection
Else
Set SrcRg = ActiveSheet.UsedRange
End If
ColCount = SrcRg.Columns.Count
Open FName For Output As #1
For Each CurrRow In SrcRg.Rows
CurrCol = 0
CurrTextStr = ""
For Each CurrCell In CurrRow.Cells
CurrCol = CurrCol + 1
CurrTextStr = CurrTextStr & CurrCell.Value & IIf(CurrCol <
ColCount, ListSep, "")
Next
Print #1, CurrTextStr
Next
Close #1
End If
End Sub


--
Jim Rech
Excel MVP
"Jac Tremblay" wrote in message
...
| Hi everyone,
|
| I get a problem with a worksheet when I export the data in a csv file. I
have a worksheet with 10 rows and 10 columns of data (100 cells). Not all of
them are filled. The last cell is J10.
| If I export this worksheet to a csv file, I get 9 commas separating the
data on each of the 10 lines. That's fine.
| If I add data in the range D11:D15, and reexport the worksheet to a csv
file, I get 10 lines with 9 commas and 5 lines with 3 commas. That's not
what I want. And that's not normal.
|
| If I use a new worksheet to test my problem, I get 15 lines with 9 commas
which is correct.
|
| What is (or may be) wrong with the first workbook?
|
| Thanks for your help.
| --
| Jac Tremblay



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default CSV File format problem

Hi Jim,
This macro does work well and I thank you for your help. But I still want to understand why one should have to use such a macro when Excel is supposed to do that job automatically.
Is it possible that some cell have a text format while the others below do not? Because, when I copy that last cell down to the last row, the problem does not appear and Excel treats these cells as if they had something in them.
I guess I will have to live with it...
Thank you again.

"Jim Rech" wrote:

Your problem seems similar to the one discussed he

http://support.microsoft.com/default...95&Product=xlw

You might have to use a macro to get the result you want. Try this one:

'Puts no quotes around strings
''Outputs the selection if more than one cell is selected, else entire sheet
''Include commas for missing items at end of row.
Sub OutputActiveSheetAsTrueCSVFileAllCommas()
Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim ListSep As String
Dim FName As Variant
Dim ColCount As Integer
Dim CurrCol As Integer
FName = Application.GetSaveAsFilename("", "CSV File (*.csv), *.csv")
If FName < False Then
ListSep = Application.International(xlListSeparator)
If Selection.Cells.Count 1 Then
Set SrcRg = Selection
Else
Set SrcRg = ActiveSheet.UsedRange
End If
ColCount = SrcRg.Columns.Count
Open FName For Output As #1
For Each CurrRow In SrcRg.Rows
CurrCol = 0
CurrTextStr = ""
For Each CurrCell In CurrRow.Cells
CurrCol = CurrCol + 1
CurrTextStr = CurrTextStr & CurrCell.Value & IIf(CurrCol <
ColCount, ListSep, "")
Next
Print #1, CurrTextStr
Next
Close #1
End If
End Sub


--
Jim Rech
Excel MVP
"Jac Tremblay" wrote in message
...
| Hi everyone,
|
| I get a problem with a worksheet when I export the data in a csv file. I
have a worksheet with 10 rows and 10 columns of data (100 cells). Not all of
them are filled. The last cell is J10.
| If I export this worksheet to a csv file, I get 9 commas separating the
data on each of the 10 lines. That's fine.
| If I add data in the range D11:D15, and reexport the worksheet to a csv
file, I get 10 lines with 9 commas and 5 lines with 3 commas. That's not
what I want. And that's not normal.
|
| If I use a new worksheet to test my problem, I get 15 lines with 9 commas
which is correct.
|
| What is (or may be) wrong with the first workbook?
|
| Thanks for your help.
| --
| Jac Tremblay



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
date format problem from opening dbf file in excel 2007 pol Excel Discussion (Misc queries) 5 December 1st 08 11:42 AM
Link from Chart File to Data File / Format Problem Brad Bross Charts and Charting in Excel 0 July 31st 08 10:15 PM
Excel file is no longer "in a recofnizable format" problem? Julie L Excel Discussion (Misc queries) 3 April 26th 08 02:12 PM
Date format/Writing to a file problem clayton Excel Discussion (Misc queries) 0 August 8th 06 01:31 AM
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? OCI Excel Programming 0 May 16th 04 10:40 PM


All times are GMT +1. The time now is 09:46 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"