Home > Software engineering >  [for] how to use VBA to read a file a particular column, if there is an empty value just delete this
[for] how to use VBA to read a file a particular column, if there is an empty value just delete this

Time:11-19

Example:
Under the specified folder in n a CSV file (data vary)
Characteristics as D column
The biggest SV, Arthur c. SV D column is null

A.C SV
A B C D E
1, 2, 3, 4, 5
A b c d e
6 7 8 9 10
Biggest SV
A B C D E
1, 2, 3, 4, 5
A b c e

6 7 8 9 10
Arthur c. SV
A B C D E
1, 2, 3, 4, 5
A b c d e


6 7 8 10
F g h I j

.
N.C SV
A B C D E
1, 2, 3, 4, 5
A b c d e

6 7 8 9 10
Such as how to delete the biggest SV and Arthur c. SV file, which need to delete the folder under particular column is null file


Thank you for the teacher ~

CodePudding user response:

Remove the beginning of a line and end of each line Spaces, as long as one line contains three Spaces are need to delete the file:
The following is the VBS example code:
 
The Set of fso=createobject (" scripting. Filesystemobject ")
Curdir=fso. Getparentfoldername (wscript. Scriptfullname)

The Set reg=createobject (" vbscript. Regexp ")
Reg. Global=True
Reg. Multiline=True
Reg. The ignorecase=True
Reg. The pattern="[] {3}"

For Each objfile In fso. Getfolder (curdir.) files
If LCase (fso) getextensionname (objfile. Name))="TXT" Then
Set the stream=fso. Opentextfile (objfile. Path, 1, False)
Blnfound=False
Do Until stream. Atendofstream
Strline=Trim (stream. Readline ())
The (strline) Then the If reg
Blnfound=True
The Exit Do
End the If
Loop
Stream. Close
If blnfound Then
Msgbox objfile. Path
'objfile. Delete True
End the If
End the If
Next

Msgbox "done!"

Run the example:


Download address:
Link: https://pan.baidu.com/s/1zV_f6cmBLsNz4VjJnatH0A
The extracted code: 3 LBK
  •  Tags:  
  • VBA
  • Related