I am trying to determine a method for 'ignoring' blank cells on a CSV file that is resulting from an Excel worksheet's data.
The blank cell will be a result from user's input in one row OR the row below (both rows will never be filled in however, the header being referenced in a script needs to remain the same). One row pertains to one OS's disk requirements while the row below it pertains to an alternative OS's disk requirements, if applicable; the format of the disk requirements will still apply to the header in its current format.
Currently when the VBA code is applied to the Excel worksheet, the missing data from the blank row pertaining to the first OS disk requirements 'pushes' the next row's information by inputting a blank cell. I would like to find a way to have the VBA code 'ignore' the blank row and have the proceeding row's data be input into this cell instead. The VBA code I am using:
Sub WriteCSVFile()
Dim My_filenumber As Integer
Dim logSTR As String
My_filenumber = FreeFile
logSTR = logSTR & "Header1" & " , "
logSTR = logSTR & "Header2" & " , "
logSTR = logSTR & "Header3" & " , "
logSTR = logSTR & "Header4" & " , "
logSTR = logSTR & "Header5" & " , "
logSTR = logSTR & "Header6" & " , "
logSTR = logSTR & "Header7" & " , "
logSTR = logSTR & "Header8" & " , "
logSTR = logSTR & "Header9" & " , "
logSTR = logSTR & "Header10" & " , "
logSTR = logSTR & "Header11" & " , "
logSTR = logSTR & "Header12" & " , "
logSTR = logSTR & "Header13" & " , "
logSTR = logSTR & Chr(13)
logSTR = logSTR & Cells(18, "C").Value & " , "
logSTR = logSTR & Cells(19, "C").Value & " , "
logSTR = logSTR & Cells(20, "C").Value & " , "
logSTR = logSTR & Cells(21, "C").Value & " , "
logSTR = logSTR & Cells(22, "C").Value & " , "
logSTR = logSTR & Cells(26, "C").Value & " , "
logSTR = logSTR & Cells(27, "C").Value & " , "
logSTR = logSTR & Cells(28, "C").Value & " , "
logSTR = logSTR & Cells(29, "C").Value & " , "
logSTR = logSTR & Cells(30, "C").Value & " , "
logSTR = logSTR & Cells(31, "C").Value & " , "
logSTR = logSTR & Cells(32, "C").Value & " , "
If there is no data resulting from logSTR = logSTR & Cells(31, "C").Value & " , " I would like to have the data from logSTR = logSTR & Cells(32, "C").Value & " , " placed in that cell rather than leaving a blank. This would allow the data's format (3 values separated by a comma) line up with Header11, Header12 and Header13 (and not Header12, Header13 and No Header).
logSTR = logSTR & Chr(13)
logSTR = logSTR & "" & " , "
logSTR = logSTR & "" & " , "
logSTR = logSTR & "" & " , "
logSTR = logSTR & "" & " , "
logSTR = logSTR & "" & " , "
logSTR = logSTR & Cells(36, "C").Value & " , "
logSTR = logSTR & Cells(37, "C").Value & " , "
logSTR = logSTR & Cells(38, "C").Value & " , "
logSTR = logSTR & Cells(39, "C").Value & " , "
logSTR = logSTR & Cells(40, "C").Value & " , "
logSTR = logSTR & Cells(41, "C").Value & " , "
logSTR = logSTR & Cells(42, "C").Value & " , "
logSTR = logSTR & Chr(13)
logSTR = logSTR & "" & " , "
logSTR = logSTR & "" & " , "
logSTR = logSTR & "" & " , "
logSTR = logSTR & "" & " , "
logSTR = logSTR & "" & " , "
logSTR = logSTR & Cells(46, "C").Value & " , "
logSTR = logSTR & Cells(47, "C").Value & " , "
logSTR = logSTR & Cells(48, "C").Value & " , "
logSTR = logSTR & Cells(49, "C").Value & " , "
logSTR = logSTR & Cells(50, "C").Value & " , "
logSTR = logSTR & Cells(51, "C").Value & " , "
logSTR = logSTR & Cells(52, "C").Value & " , "
Open "Z:\SHARED DRIVE\RequestDirectory\" & ThisWorkbook.Name & ".csv" For Append As #My_filenumber
Print #My_filenumber, logSTR
Close #My_filenumber
End Sub