KevinNassauNY
Programmer
The solution from a previous thread about this did not work for me. It only deleted the column header, none of the data. The reason being the line that measures the UBOUND of ClippedArray was not working. To get around that, I simply looped through the text object line by line. In the following example, I remove column 20 from the input file. This works for me:
and if you want to delete several columns at once, you could replace this line:
If intCount <> (CutColumn -1) Then
with something like this:
If intCount <> (3 OR 19 OR 24 OR 26) Then ....
(but here you subtract one (-1) from each column you want to remove since they are zero based and you are supplying literals)
Enjoy!
Code:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, strLine, dataArray, clippedArray()
InputFile="C:\Users\kevind\Desktop\InSight_Inbound_View_Download.csv"
OutputFile="C:\Users\kevind\Desktop\InSight_Inbound_View_Download_New.csv"
Set fso = CreateObject("Scripting.FileSystemObject")
Set InFile = fso.OpenTextFile(InputFile, ForReading)
Set OutFile = fso.OpenTextFile(OutputFile, ForWriting, True)
Do While InFile.AtEndOfStream <> True
strLine = InFile.ReadLine
ReDim Preserve clippedArray(x)
clippedArray(x) = Split(strLine,",")
CutColumn = 20 ' The column I want to delete
intCount = 0
newLine = ""
For Each Element In clippedArray(x)
If intCount <> (CutColumn -1) Then
EndChar = ","
newLine = newLine & Element & EndChar
End If
intCount = intCount + 1
Next
OutFile.WriteLine newLine
Loop
InFile.Close
OutFile.Close
WScript.Echo "Done"
and if you want to delete several columns at once, you could replace this line:
If intCount <> (CutColumn -1) Then
with something like this:
If intCount <> (3 OR 19 OR 24 OR 26) Then ....
(but here you subtract one (-1) from each column you want to remove since they are zero based and you are supplying literals)
Enjoy!