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 & "\" & GMCCard)
End If
Windows(GMCCard).Activate
Sheets("gmc_Metrics"
.Visible = True
Worksheets("gmc_Metrics"
.Activate
Set ExpRng = Range("a2:c272"
NumCols = ExpRng.Columns.Count
NumRows = ExpRng.Rows.Count
filename = "c:\Metrics.csv"
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 = ""
If c <> NumCols And Date_Data < 20030404 Then
Write #1, Data;
Else
'Write #1, Data
End If
Next c
Next r
Close #1
Sheets("Metrics"
.Visible = False
If CallingWorkbook <> Card Then
ActiveWorkbook.Close
End If
retValue = True
GoTo noerror
errorStuff:
retValue = False
noerror:
ExportMetricsInCSV = retValue
End Function
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 & "\" & GMCCard)
End If
Windows(GMCCard).Activate
Sheets("gmc_Metrics"
Worksheets("gmc_Metrics"
Set ExpRng = Range("a2:c272"
NumCols = ExpRng.Columns.Count
NumRows = ExpRng.Rows.Count
filename = "c:\Metrics.csv"
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 = ""
If c <> NumCols And Date_Data < 20030404 Then
Write #1, Data;
Else
'Write #1, Data
End If
Next c
Next r
Close #1
Sheets("Metrics"
If CallingWorkbook <> Card Then
ActiveWorkbook.Close
End If
retValue = True
GoTo noerror
errorStuff:
retValue = False
noerror:
ExportMetricsInCSV = retValue
End Function