Re: Delete Rows Based On Condition Of 1 Column
Examining the file in notepad shows it to be comma delimited BUT each field also has a fixed length, padded out with spaces.
The closest I got to replicating your file structure (by bringing the file into a sheet) was by changing the extension to .txt as parsnip suggested and opening it in Excel, choosing ',' as the delimiter (a comma), making sure all columns were imported as Text. Then I deleted a few rows and used Save As to save the file as a csv file, (the first csv option in the list).
The saved file might be usable in your Analyser, but the differences included:
1. Where your original file had no data beyond the MYCALC field it would have nothing. In the saved file there was a string of commas one per missing field datum.
2. There was an extra field on most lines of the new file where there wasn't one on the original file. Further investigation reveals that your original file's header has an extra comma with no field heading.
So I reckon only a 40% chance of it being readable and it would need verifying even if it were readable. However, this method would be the easiest for you to delete the lines you need to delete as you can use all the facilities available to you that a spreadsheet offers to help in that. Another difficulty encountered was writing a macro to automate the importing to a sheet; there are so many fields per record that Excel complained that the lines of code were too long or used "too many line continuations", it crashed Excel a couple of times. So I doubt I could do much to automate the process using this method.
I had much better results with just using Excel to read the original file one line at a time and write that line to a new file if it didn't match your criterion. The resultant files were identical to the original, bar the skipped rows. Now to hope that your Analyser doesn't throw a wobbly if there are fewer lines than it expects in a file, otherwise I'm more than 99% sure it will be readable.
Could you run this macro for me and test the resultant file in the Analyser? If it likes it, I/you can develop it further, principally to make it more user fiendly (oops, friendly). You'll have to change the lines with the file names to suit your folder structure and file names. The bit which skips the writing of the lines you want skipped is:
If Val(Flds(35)) <> 5 Then
Sub blah()
src = FreeFile
Open "C:\Documents and Settings\xxxxx\My Documents\test\test.csv" For Input As src
dest = FreeFile
Open "C:\Documents and Settings\xxxxx\My Documents\test\Dest test.csv" For Output As dest
Do While Not EOF(src)
Line Input #src, data
Flds = Split(data, ",")
If Val(Flds(35)) <> 5 Then
Print #dest, data
End If
Loop
Close #src
Close #dest
End Sub
Display More
p45cal