I have simple code that creates a csv from a table that works perfectly but I need to iterate through the data in the table and remove any 0
's (any cell that contains the number 0
as the table has equations) before it writes to the output file. I can't simply modify my equations in the table with an if statement to return " "
as the output file I'm creating will simply add a space in the output csv, which is just as bad. I'm using the output file as a input file for a script using Pascal and it would just skew the data it's pasting because of the " "
(space).
I've tried using the below in my code and it does not work.
If csvVal = 0 Then
csvVal.Replace What:=0, Replacement:=vbNullString, Lookat:=xlWhole
End If
Sub saveTableToCSV2()
Dim tbl As ListObject
Dim csvFilePath As String
Dim fNum As Integer
Dim tblArr
Dim rowArr
Dim csvVal
Dim csvVal2 As Object
Dim r As Range
Set tbl = Worksheets("FDA TOOL").ListObjects("tblFDAinfo")
csvFilePath = "F:\Scripting\Import\Wal-Mart\Zac\Audit_Tool2FDA.csv"
tblArr = tbl.DataBodyRange.Value
fNum = FreeFile()
Open csvFilePath For Output As #fNum
For i = 1 To UBound(tblArr)
rowArr = Application.Index(tblArr, i, 0)
csvVal = VBA.Join(rowArr, ",")
If csvVal = 0 Then
csvVal.Replace What:=0, Replacement:=vbNullString, Lookat:=xlWhole
End If
Print #1, csvVal
Next
Close #fNum
Set tblArr = Nothing
Set rowArr = Nothing
Set csvVal = Nothing
End Sub
I'd like to remove any 0's before it writes to the output file.
Below is what it is returning for the first line of the table.
REP,RAD,130,4,CT,RB1,,,200,PCS,ACC,17389,96R--CR,,,0,,,,,0,
I would like it to return:
REP,RAD,130,4,CT,RB1,,,200,PCS,ACC,17389,96R--CR,,,,,,,,,