Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Avoid importing 65,536 rows

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
access user - 18 Mar 2008 12:50 GMT
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
Joel - 18 Mar 2008 13:16 GMT
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

> Hi
>
[quoted text clipped - 6 lines]
> tia
> James
access user - 18 Mar 2008 13:19 GMT
Wow - I'll give that a go - let you know how I get on.
thanks
James

> The code below will write a CSV file and will not output anything for a blank
> line
[quoted text clipped - 49 lines]
> > tia
> > James
access user - 18 Mar 2008 15:05 GMT
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

> The code below will write a CSV file and will not output anything for a blank
> line
[quoted text clipped - 49 lines]
> > tia
> > James
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.