Vba Count Rows In A Text File

Posted on admin
Vba Count Rows In A Text File Average ratng: 4,6/5 3980 reviews

Using Vba To Count Rows In Text File And Output Results To An Excel Spreadsheet - Hey I am trying to create a small macro that will. - Free Excel Help. Using Vba To Count Rows In Text File And Output Results To An Excel Spreadsheet - Hey I am trying to create a small macro that will. - Free Excel Help.

  1. See More On Stackoverflow

Hi, Background: I have 15 text and csv files that I need to count before I import them into Access. What is the best way to do this? (I'm running Access 2010 and 2013)? I have seen the brute force method where you open the file and read in each record while incrementing a counter. I've also seen the following code: Const ForReading = 1 Set objFSO = CreateObject('Scripting.FileSystemObject') Set objTextFile = objFSO.OpenTextFile ('C: Scripts Test.txt', ForReading) objTextFile.ReadAll Wscript.Echo 'Number of lines: ' & objTextFile.Line Question: What is the best / fastest way to count the number of lines in a text and / or csv table? Dennis Solis. Question: What is the best / fastest way to count the number of lines in a text and / or csv table?

Vba Count Rows In A Text File

See More On Stackoverflow

Hi Dennis, One way or the other you have to go through the file to count the number of lines. This can be done with simple code (your 'brute force') by reading line by line and counting them, or 'hidden' in a method of an object. Which of the two is the fastest can be checked very easily. Which of the two is the best way depends on the organization of your code, and it is only you who can answer that. A little bit 'conservative', I use the simple line counting way, and I am quite happy with it.

In fact it is the same systematics as you will use in the next passage of the file to process the individual lines. Question: What is the best / fastest way to count the number of lines in a text and / or csv table? Hi Dennis, One way or the other you have to go through the file to count the number of lines. This can be done with simple code (your 'brute force') by reading line by line and counting them, or 'hidden' in a method of an object. Which of the two is the fastest can be checked very easily.

Which of the two is the best way depends on the organization of your code, and it is only you who can answer that. A little bit 'conservative', I use the simple line counting way, and I am quite happy with it. In fact it is the same systematics as you will use in the next passage of the file to process the individual lines. I was hoping there was a method similar to the access data base method where you can open the file, goto the last record, and get the record count.

Rows

Hi Dennis, In the header of Word documents you can see how many lines and characters the document has. But that is at the cost of quite some overhead. In flat files (as.txt or.csv) there is no such information. But it is not that brute force.

It is like in Access where you want to know how many records there are in a RecordSet. You only know that figure when you have 'processed' them all. Unfortunately, I am not processing word filed.

But I did the brute force way and I was pleasantly surprised. Below is a table of my results, but basically even the big tables were counted in only 1 or 2 seconds. A 19 meg file with 19,343 records (with 1k record size) took 1 second A 3 meg file with 35,000 records took less than a second. A 5 meg file with 22,000 records look less than a second. As a matter of fact, Access processed 3 files in less than a second for a total of 30,000 rows Granted, I have an I7 process with 8 gb of mem and SATA 3 drives, Even though I have a fast machine with lots of memory, I'm pretty impressed with this solution. Dennis Solis.