PC Review


Reply
Thread Tools Rate Thread

Avoid importing 65,536 rows

 
 
access user
Guest
Posts: n/a
 
      18th Mar 2008
Hi

I have created a csv file to import into an external program, and regardless
of how many rows are populated, the other program attempts to import ALL
65,536 rows in the csv file. Is there something I can do, within Excel,
preferably programatically, to ensure that only rows with data are presented
for import.

tia
James
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      18th Mar 2008
The code below will write a CSV file and will not output anything for a blank
line

Sub WriteCSV()

Const MyPath = "C:\temp\"
Const WriteFileName = "text.csv"

Const Delimiter = ","

Const ForReading = 1, ForWriting = 2, ForAppending = 3

Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

Set fswrite = CreateObject("Scripting.FileSystemObject")

'open files
WritePathName = MyPath + WriteFileName
fswrite.CreateTextFile WritePathName
Set fwrite = fswrite.GetFile(WritePathName)
Set tswrite = fwrite.OpenAsTextStream(ForWriting, TristateUseDefault)

LastRow = Cells(Rows.Count, "A").End(xlUp).Row

For RowCount = 1 To LastRow
LastCol = Cells(RowCount, Columns.Count).End(xlToLeft).Column
For ColCount = 1 To LastCol
If ColCount = 1 Then
OutputLine = Cells(RowCount, ColCount)
Else
OutputLine = OutputLine & Delimiter & Cells(RowCount, ColCount)
End If
Next ColCount
OutputLine = Trim(OutputLine)
If Len(OutputLine) <> 0 Then
tswrite.writeline OutputLine
End If
Next RowCount

tswrite.Close

End Sub

"access user" wrote:

> Hi
>
> I have created a csv file to import into an external program, and regardless
> of how many rows are populated, the other program attempts to import ALL
> 65,536 rows in the csv file. Is there something I can do, within Excel,
> preferably programatically, to ensure that only rows with data are presented
> for import.
>
> tia
> James

 
Reply With Quote
 
access user
Guest
Posts: n/a
 
      18th Mar 2008
Wow - I'll give that a go - let you know how I get on.
thanks
James

"Joel" wrote:

> The code below will write a CSV file and will not output anything for a blank
> line
>
> Sub WriteCSV()
>
> Const MyPath = "C:\temp\"
> Const WriteFileName = "text.csv"
>
> Const Delimiter = ","
>
> Const ForReading = 1, ForWriting = 2, ForAppending = 3
>
> Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
>
> Set fswrite = CreateObject("Scripting.FileSystemObject")
>
> 'open files
> WritePathName = MyPath + WriteFileName
> fswrite.CreateTextFile WritePathName
> Set fwrite = fswrite.GetFile(WritePathName)
> Set tswrite = fwrite.OpenAsTextStream(ForWriting, TristateUseDefault)
>
> LastRow = Cells(Rows.Count, "A").End(xlUp).Row
>
> For RowCount = 1 To LastRow
> LastCol = Cells(RowCount, Columns.Count).End(xlToLeft).Column
> For ColCount = 1 To LastCol
> If ColCount = 1 Then
> OutputLine = Cells(RowCount, ColCount)
> Else
> OutputLine = OutputLine & Delimiter & Cells(RowCount, ColCount)
> End If
> Next ColCount
> OutputLine = Trim(OutputLine)
> If Len(OutputLine) <> 0 Then
> tswrite.writeline OutputLine
> End If
> Next RowCount
>
> tswrite.Close
>
> End Sub
>
> "access user" wrote:
>
> > Hi
> >
> > I have created a csv file to import into an external program, and regardless
> > of how many rows are populated, the other program attempts to import ALL
> > 65,536 rows in the csv file. Is there something I can do, within Excel,
> > preferably programatically, to ensure that only rows with data are presented
> > for import.
> >
> > tia
> > James

 
Reply With Quote
 
access user
Guest
Posts: n/a
 
      18th Mar 2008
Hi Joel

I get an error

'argument not optional' on line beginning LastRow =

Also, one thing I didn't mention, the worksheet from which the csv file is
to be created is within a workbook, so do we also need to use the With
statement to tell it which worksheet?

tia
James

"Joel" wrote:

> The code below will write a CSV file and will not output anything for a blank
> line
>
> Sub WriteCSV()
>
> Const MyPath = "C:\temp\"
> Const WriteFileName = "text.csv"
>
> Const Delimiter = ","
>
> Const ForReading = 1, ForWriting = 2, ForAppending = 3
>
> Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
>
> Set fswrite = CreateObject("Scripting.FileSystemObject")
>
> 'open files
> WritePathName = MyPath + WriteFileName
> fswrite.CreateTextFile WritePathName
> Set fwrite = fswrite.GetFile(WritePathName)
> Set tswrite = fwrite.OpenAsTextStream(ForWriting, TristateUseDefault)
>
> LastRow = Cells(Rows.Count, "A").End(xlUp).Row
>
> For RowCount = 1 To LastRow
> LastCol = Cells(RowCount, Columns.Count).End(xlToLeft).Column
> For ColCount = 1 To LastCol
> If ColCount = 1 Then
> OutputLine = Cells(RowCount, ColCount)
> Else
> OutputLine = OutputLine & Delimiter & Cells(RowCount, ColCount)
> End If
> Next ColCount
> OutputLine = Trim(OutputLine)
> If Len(OutputLine) <> 0 Then
> tswrite.writeline OutputLine
> End If
> Next RowCount
>
> tswrite.Close
>
> End Sub
>
> "access user" wrote:
>
> > Hi
> >
> > I have created a csv file to import into an external program, and regardless
> > of how many rows are populated, the other program attempts to import ALL
> > 65,536 rows in the csv file. Is there something I can do, within Excel,
> > preferably programatically, to ensure that only rows with data are presented
> > for import.
> >
> > tia
> > James

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use SUMPRODUCT and avoid rows with #REF! =?Utf-8?B?UmF1bA==?= Microsoft Excel Programming 2 3rd Nov 2007 02:25 AM
How to avoid deleting of rows 2foot Microsoft Excel Programming 2 5th Jun 2006 09:57 AM
how do i avoid truncation when importing text file into MS access =?Utf-8?B?cmVuaXc5Ng==?= Microsoft Access External Data 2 19th Oct 2005 11:27 PM
How to avoid deleteing certain rows? E.J. van Wijngaarden Microsoft Excel Programming 0 16th Jun 2005 05:23 PM
avoid importing hidden excel columns Laura via AccessMonster.com Microsoft Access External Data 0 20th Apr 2005 07:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:37 PM.