Excel VBA Exporting CSV

joes2007

New Member
Joined
Jan 10, 2018
Messages
18
I currently have and use some code that exports a range as a CSV. It has done everything I need up until now. I need to export data that contains commas. I need to export the data as a .CSV for the next step of my operation, but I need it delimited by something other than a comma.

Does anyone have any thoughts?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You can put quotes around values to allow commas to be exported:

a,b,c,"d,e",f,g,"h,i",j


Book1
ABCDEFGH
1abcd,efgh,ij
test


WBD
 
Upvote 0
Sorry, here is the code.

Code:
Private Sub sh05_print_Click()


Call unlocksheet


'to export data to csv -- ends with calling the 'clear' sub


Dim TextFile As Integer
Dim FilePath As String
Dim record_num As Integer
Dim record_count As Integer
Dim column_num As Integer
record_count = Range("aa4").Value
FilePath = "C:\Bartender Commander Folder\SH_05_PART_LABELS.csv"
TextFile = FreeFile
Open FilePath For Output As TextFile
For record_num = 1 To record_count
        For column_num = 1 To 8
            If column_num = 8 Then
                Write [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=TextFile]#TextFile[/URL] , Range("aa7:af10").Cells(record_num, column_num).Value
            Else
                Write [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=TextFile]#TextFile[/URL] , Range("aa7:af10").Cells(record_num, column_num).Value,
            End If
        Next column_num
Next record_num
Close TextFile




Call locksheet


Call sh05clear_Click
End Sub
 
Upvote 0
I had a cell that was performing a vlookup and the return had a comma in it. I could not get concat to work with double quotes. This ended up working: CONCATENATE(char(34); B2 ;char(34))

Thank you for your help!
 
Upvote 0
Problem not solved! The delimiting problem is but a new one is now here. This data gets embedded into a 2d barcode, later scanned and delimited by power query. Power query is separating ["test, inc"] into ["test] and [inc"].

Thoughts?
 
Upvote 0
The barcode is generated by BarTender, I will have it encode ; as the delimiter and then power query delimit by that. Thanks all!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top