By: Lutfor Rahman Shimanto

In reply to Luke.

Hello Luke

Thanks for sharing your problem with such clarity. Based on your requirements, you can use the following Excel VBA Sub-procedure to fulfil your goal.

Excel VBA Sub-procedure:

Sub ExcelToCSV()

Dim rng As Range, row As Range, cell As Range
Dim dqt As String, dlim As String, text As String
Dim file As Variant
On Error Resume Next

Set rng = ActiveSheet.Range("A3:B319, D3:F319, I3:I319")

If rng Is Nothing Then Exit Sub

file = Application.GetSaveAsFilename("", "CSV File (*.csv), *.csv")
dlim = Application.International(xlListSeparator)
Open file For Output As #1
For Each row In rng.Rows
dqt = ""
For Each cell In row.Cells

If cell.Column = 1 Or cell.Column = 2 Or cell.Column = 4 Or cell.Column = 5 Or cell.Column = 6 Or cell.Column = 9 Then
dqt = dqt & """" & cell.Value & """" & dlim
Else
dqt = dqt & cell.Value & dlim
End If
Next
While Right(dqt, 1) = dlim
dqt = Left(dqt, Len(dqt) - 1)
Wend
Print #1, dqt
Next
Close #1
If Err = 0 Then MsgBox "The CSV file has been saved to: " & file, vbInformation

End Sub

Hopefully, the sub-procedure will be helpful. Stay blessed.

Regards
Lutfor Rahman Shimanto
Excel & VBA Developer
ExcelDemy