Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default exporting CSV numbers become text

I have an xls 2003 file with dates, text and currency values. I need to run a
macro to export to a CSV format. When run, the currency values convert to
text. I've tried various "pastespecial" options. But when I get the currency
to show up as numbers, the dates show up unformatted as integers, too.

Here is a sample of the Excel data:
1/3/2005 5.03.h.1 District 287 $65,658 Carl Perkins Grant
1/3/2005 5.03.h.2 District 287 $7,525 Tech Prep Grant

Here is what it looks like after a typical "pastespecial":
1/3/2005,5.03.h.1, 287,"$65,658",Carl Perkins Grant
1/3/2005,5.03.h.2, 287,"7,525",Tech Prep Grant

Here is my code:

Sub ExportToCSV()
' Save selected range as a CSV text file
Dim ThisBook As Workbook

ChDrive "S"
ChDir "S:\TECH\GEORGE\"

Set ThisBook = ActiveWorkbook
Selection.Copy

Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues ' one of several options used
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="TestForRichard.txt", FileFormat:=xlCSV
ActiveWorkbook.Close
Application.DisplayAlerts = True
ThisBook.Activate

End Sub

By the way, the exact range can change, meaning that the columns are NOT
always in the positions shown!

Thanks for any ideas or a thwack on the head for overlooking something
obvious.

George
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default exporting CSV numbers become text

Your problem is with the Coma in the currency. In order to represent the coma
it has to put the value in quotes. You will need to have your sub do some
best guess to determine what needs to be converted to an unformatted number
and what can be left alone. You can use the isdate function to determine what
columns are dates and convert the rest of the sheet to unformatted numbers. I
am afraid I have to go now so I can't be more help than that...
--
HTH...

Jim Thomlinson


"GeorgeAtkins" wrote:

I have an xls 2003 file with dates, text and currency values. I need to run a
macro to export to a CSV format. When run, the currency values convert to
text. I've tried various "pastespecial" options. But when I get the currency
to show up as numbers, the dates show up unformatted as integers, too.

Here is a sample of the Excel data:
1/3/2005 5.03.h.1 District 287 $65,658 Carl Perkins Grant
1/3/2005 5.03.h.2 District 287 $7,525 Tech Prep Grant

Here is what it looks like after a typical "pastespecial":
1/3/2005,5.03.h.1, 287,"$65,658",Carl Perkins Grant
1/3/2005,5.03.h.2, 287,"7,525",Tech Prep Grant

Here is my code:

Sub ExportToCSV()
' Save selected range as a CSV text file
Dim ThisBook As Workbook

ChDrive "S"
ChDir "S:\TECH\GEORGE\"

Set ThisBook = ActiveWorkbook
Selection.Copy

Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues ' one of several options used
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="TestForRichard.txt", FileFormat:=xlCSV
ActiveWorkbook.Close
Application.DisplayAlerts = True
ThisBook.Activate

End Sub

By the way, the exact range can change, meaning that the columns are NOT
always in the positions shown!

Thanks for any ideas or a thwack on the head for overlooking something
obvious.

George

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default exporting CSV numbers become text

Hi

Try this amended routine:

Regards,
Andrew
excelthoughts.com

Sub ExportToCSV()
' Save selected range as a CSV text file
Dim ThisBook As Workbook
Dim thisSheet As Worksheet
Dim thisSelection As Range
Dim newBook As Workbook
Dim NewSheet As Worksheet
Dim cell As Range

ChDrive "S"
ChDir "S:\TECH\GEORGE\"

Set ThisBook = Selection.Parent.Parent
Set thisSheet = ThisBook.ActiveSheet
Set thisSelection = Selection

thisSelection.Copy

Set newBook = Workbooks.Add
Set NewSheet = newBook.ActiveSheet

ActiveCell.PasteSpecial Paste:=xlPasteValues ' one of several options
used

For Each cell In Range(thisSheet.Cells(1),
thisSheet.Cells(thisSelection.Columns.Count))

If IsDate(cell.Value) Then
cell.EntireColumn.Copy
NewSheet.Cells(1, cell.Column).PasteSpecial
Paste:=xlPasteFormats
End If
Next

Application.DisplayAlerts = False
newBook.SaveAs Filename:="TestForRichard.txt", FileFormat:=xlCSV
newBook.Close
Application.DisplayAlerts = True
ThisBook.Activate


End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default exporting CSV numbers become text

Thanks, Jim. I should have thought of that!
George

"Jim Thomlinson" wrote:

Your problem is with the Coma in the currency. In order to represent the coma
it has to put the value in quotes. You will need to have your sub do some
best guess to determine what needs to be converted to an unformatted number
and what can be left alone. You can use the isdate function to determine what
columns are dates and convert the rest of the sheet to unformatted numbers. I
am afraid I have to go now so I can't be more help than that...
--
HTH...

Jim Thomlinson


"GeorgeAtkins" wrote:

I have an xls 2003 file with dates, text and currency values. I need to run a
macro to export to a CSV format. When run, the currency values convert to
text. I've tried various "pastespecial" options. But when I get the currency
to show up as numbers, the dates show up unformatted as integers, too.

Here is a sample of the Excel data:
1/3/2005 5.03.h.1 District 287 $65,658 Carl Perkins Grant
1/3/2005 5.03.h.2 District 287 $7,525 Tech Prep Grant

Here is what it looks like after a typical "pastespecial":
1/3/2005,5.03.h.1, 287,"$65,658",Carl Perkins Grant
1/3/2005,5.03.h.2, 287,"7,525",Tech Prep Grant

Here is my code:

Sub ExportToCSV()
' Save selected range as a CSV text file
Dim ThisBook As Workbook

ChDrive "S"
ChDir "S:\TECH\GEORGE\"

Set ThisBook = ActiveWorkbook
Selection.Copy

Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues ' one of several options used
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="TestForRichard.txt", FileFormat:=xlCSV
ActiveWorkbook.Close
Application.DisplayAlerts = True
ThisBook.Activate

End Sub

By the way, the exact range can change, meaning that the columns are NOT
always in the positions shown!

Thanks for any ideas or a thwack on the head for overlooking something
obvious.

George

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default exporting CSV numbers become text

Thanks, Andrew. Good work. I must have got distracted by preoccupation of the
PasteSpecial command and didn't think through logically. You and Jim have put
me back on track.
George

"excelthoughts" wrote:

Hi

Try this amended routine:

Regards,
Andrew
excelthoughts.com

Sub ExportToCSV()
' Save selected range as a CSV text file
Dim ThisBook As Workbook
Dim thisSheet As Worksheet
Dim thisSelection As Range
Dim newBook As Workbook
Dim NewSheet As Worksheet
Dim cell As Range

ChDrive "S"
ChDir "S:\TECH\GEORGE\"

Set ThisBook = Selection.Parent.Parent
Set thisSheet = ThisBook.ActiveSheet
Set thisSelection = Selection

thisSelection.Copy

Set newBook = Workbooks.Add
Set NewSheet = newBook.ActiveSheet

ActiveCell.PasteSpecial Paste:=xlPasteValues ' one of several options
used

For Each cell In Range(thisSheet.Cells(1),
thisSheet.Cells(thisSelection.Columns.Count))

If IsDate(cell.Value) Then
cell.EntireColumn.Copy
NewSheet.Cells(1, cell.Column).PasteSpecial
Paste:=xlPasteFormats
End If
Next

Application.DisplayAlerts = False
newBook.SaveAs Filename:="TestForRichard.txt", FileFormat:=xlCSV
newBook.Close
Application.DisplayAlerts = True
ThisBook.Activate


End Sub


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
Exporting numbers from Sql Server to Excel becomes text doofy Charts and Charting in Excel 0 December 18th 07 05:36 PM
Exporting Time Formatted Numbers inside Macros Don Excel Worksheet Functions 4 November 28th 06 07:56 PM
Mix of numbers/letters in same column - Error exporting Malte Sievers Excel Discussion (Misc queries) 1 December 2nd 05 01:03 AM
Exporting From Quickbooks-not formatting numbers Carrie Excel Discussion (Misc queries) 1 July 22nd 05 11:58 PM
Exporting numbers into Excel shedevel143 Excel Discussion (Misc queries) 1 December 11th 04 12:37 PM


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