Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write Data??????

Status
Not open for further replies.

q4s72534

MIS
Aug 19, 2003
59
US
I'm having trouble writing data to a file

example


My excel file to export is below:

Invol Postpaid Churn 20030201 0.00%
Invol Postpaid Churn 20030301 0.00%
Invol Postpaid Churn 20030401 0.00%
Invol Postpaid Churn 20030501 0.00%
Invol Postpaid Churn 20030601 0.00%


I want my file to look like this after the file is exported

Invol Postpaid Churn 20030201 0.00%
Invol Postpaid Churn 20030301 0.00%
Invol Postpaid Churn 20030401 0.00%
Invol Postpaid Churn 20030501 0.00%
Invol Postpaid Churn 20030601 0.00%

instead my code creates a file like this "on one line"

Invol PostpaidChur 2003020 0.00% Invol Postpaid Churn....


what do i need to change in my code. thank you so much for your help. i'm so blessed to have this help.


Public Function Export() As Boolean
On Error GoTo errorStuff

Dim retValue As Boolean
retValue = False
Dim filename As String
Dim NumRows As Long, NumCols As Integer
Dim r As Long, c As Integer
Dim Data
Dim Date_Data
Dim ExpRng As Range
Dim CallingWorkbook As String
CallingWorkbook = ActiveWorkbook.name
If CallingWorkbook <> Card Then
Workbooks.Open (BaseDirectory & &quot;\&quot; & GMCCard)
End If
Windows(GMCCard).Activate
Sheets(&quot;gmc_Metrics&quot;).Visible = True
Worksheets(&quot;gmc_Metrics&quot;).Activate
Set ExpRng = Range(&quot;a2:c272&quot;)
NumCols = ExpRng.Columns.Count
NumRows = ExpRng.Rows.Count
filename = &quot;c:\Metrics.csv&quot;
Open filename For Output As #1
For r = 1 To NumRows
For c = 1 To NumCols
Data = ExpRng.Cells(r, c).Value
Date_Data = ExpRng.Cells(r, 2).Value
If IsNumeric(Data) Then Data = Val(Data)
If IsEmpty(ExpRng.Cells(r, c)) Then Data = &quot;&quot;
If c <> NumCols And Date_Data < 20030404 Then
Write #1, Data;
Else
'Write #1, Data
End If
Next c
Next r
Close #1
Sheets(&quot;Metrics&quot;).Visible = False
If CallingWorkbook <> Card Then
ActiveWorkbook.Close
End If
retValue = True
GoTo noerror
errorStuff:
retValue = False
noerror:
ExportMetricsInCSV = retValue
End Function
 
I think that after each libe of data has finished you need to put a line in that forces a new line

heres an extract from something I am writing I know this works should give you an idea.

ts.write &quot;********************************************************************&quot;
ts.writeblanklines (1)
ts.write &quot;* *&quot;
ts.writeblanklines (1)
ts.write &quot;* THIS FILE IS THE PROPERTY OF THE COCA COLA COMPANY *&quot;
ts.writeblanklines (1)
ts.write &quot;* This file is classified HIGHLY CONFIDENTIAL *&quot;
ts.writeblanklines (1)
ts.write &quot;* Any attempt to interfer with this file is a criminal offence *&quot;
ts.writeblanklines (1)
ts.write &quot;* *&quot;
ts.writeblanklines (1)
ts.write &quot;*******************************************************************&quot;
ts.writeblanklines (1)
ts.write &quot;Copyright The Coca Cola Company - 2003&quot;
ts.writeblanklines (1)
Do While varpos < 26
ts.write secure(varpos)
ts.writeblanklines (1)
varpos = varpos + 1
Loop


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top