LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Numbers 0000 will = 0 when converted to a csv file via macro

Numbers 0000 will = 0 when converted to a csv file via macro. i want my 0000
to be the value in the csv file not just 0 and 0999 to be a value not 999.
this is very important to port phone numbers in to database. the spreadsheet
has a format of text and a data validation of length 4 characters as a min
and a max. i have a 41 sheet spreadsheet with multiple columns. here is the
current macro: Please let me know what i can do, thanks.



Public Sub DoTheExport()
Dim FName As Variant
Dim Sep As String
Dim wsSheet As Worksheet
Dim nFileNum As Integer

'**** Allows you to choose your delimenter - advised not to use comma
Sep = InputBox("Enter a single delimiter character (e.g., pipe or
semi-colon)", _
"Export To Text File")


For Each wsSheet In Worksheets
wsSheet.Activate

'**** make all cells in upper case
' Sub makeupper()
For Each c In ActiveSheet.UsedRange
If Not c.HasFormula Then c.Value = UCase(c)
Next
' End Sub
'*****

nFileNum = FreeFile
Open "C:\00_Mintz\CSG_Proj\PROJECTS\baselines\Carol_Qui nn\CSV\" &
wsSheet.Name & ".csv" For Output As #nFileNum
ExportToTextFile CStr(nFileNum), Sep, False
'_
' MsgBox("Do You Want To Export The Entire Worksheet?", _
' vbYesNo, "Export To Text File") = vbNo
Close nFileNum
Next wsSheet

End Sub

Public Sub ExportToTextFile(nFileNum As Integer, _
Sep As String, SelectionOnly As Boolean)

Dim WholeLine As String
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer
Dim CellValue As String

'--------------------------------------
' The following if statement allows you to choose
' selection or the whole sheet to be converted
Application.ScreenUpdating = False
On Error GoTo EndMacro:

If SelectionOnly = True Then
With Selection
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
Else
With ActiveSheet.UsedRange
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With
End If
'--------------------------------------

For RowNdx = StartRow + 1 To EndRow 'skips the header
WholeLine = ""
For ColNdx = StartCol To EndCol
If Cells(RowNdx, ColNdx).Value = "" Then
CellValue = "" 'configures values around the comma values
Else
CellValue = _
Application.WorksheetFunction.Text _
(Cells(RowNdx, ColNdx).Value, _
Cells(RowNdx, ColNdx).NumberFormat)
End If
WholeLine = WholeLine & CellValue & Sep
Next ColNdx
WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
Print #nFileNum, WholeLine
Next RowNdx

EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True

End Sub





thanks in advance
cg
 
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
trying to change 000-000-0000 phone format to (000)000-0000 ???? Labtyda Excel Worksheet Functions 5 March 10th 08 08:19 PM
excel 2003 file converted to .xlsm file when save to network drive Chris Excel Discussion (Misc queries) 3 January 23rd 08 02:56 PM
How can I get 0000 in Every Column N every Excel file by default? Sanjeev Excel Discussion (Misc queries) 2 November 15th 06 09:34 PM
what is the minimum numbers set for 4 digit numbers from 0000 to 9 Ambika Excel Discussion (Misc queries) 14 January 27th 06 10:50 PM
Phone number format from 000.000.0000 to (000)000-0000 Janice Excel Discussion (Misc queries) 4 June 24th 05 12:46 AM


All times are GMT +1. The time now is 07:43 PM.

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

About Us

"It's about Microsoft Excel"