Hello, my script for removing columns within a .csv file works for only removing 1 column and i'm not sure why. Even if I have 2 CutColumn commands, it only removes the last column specified. In example below, it only removes the 1st column, not the 2nd. I'm also going to need to remove all rows that do not contain a certain string in a certain column. Help would be greatly appreciated. Thanks in advance.
'On Error Resume Next
Dim objFSO, dataArray, clippedArray()
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Create an array out of the CSV
'open the data file
Set oTextStream = objFSO.OpenTextFile("C:\test\test.csv")
Set newFile = objFSO.CreateTextFile("C:\test\test_new.csv")
'make an array from the data file
dataArray = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
x = 0
For Each strLine In dataArray
'Now make an array from each line
ReDim Preserve clippedArray(x)
clippedArray(x) = Split(strLine,",")
' Delete Fields
CutColumn = 2
CutColumn
intCount = 0
newLine = ""
For Each Element In clippedArray(x)
If intCount = UBound(clippedArray(x)) Then
EndChar = vbCrLf
Else
EndChar = ","
End If
If intCount <> CutColumn -1 Then
newLine = newLine & Element & EndChar
End If
intCount = intCount + 1
If intCount = UBound(clippedArray(x))+1 Then
newFile.Write newLine
End If
Next
Next
'On Error Resume Next
Dim objFSO, dataArray, clippedArray()
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Create an array out of the CSV
'open the data file
Set oTextStream = objFSO.OpenTextFile("C:\test\test.csv")
Set newFile = objFSO.CreateTextFile("C:\test\test_new.csv")
'make an array from the data file
dataArray = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
x = 0
For Each strLine In dataArray
'Now make an array from each line
ReDim Preserve clippedArray(x)
clippedArray(x) = Split(strLine,",")
' Delete Fields
CutColumn = 2
CutColumn
intCount = 0
newLine = ""
For Each Element In clippedArray(x)
If intCount = UBound(clippedArray(x)) Then
EndChar = vbCrLf
Else
EndChar = ","
End If
If intCount <> CutColumn -1 Then
newLine = newLine & Element & EndChar
End If
intCount = intCount + 1
If intCount = UBound(clippedArray(x))+1 Then
newFile.Write newLine
End If
Next
Next