Creating a CSV with VBA

joes2007

New Member
Joined
Jan 10, 2018
Messages
18
I have an 'application' that is used to take supplied information from the user, query our SQL server, mate up some information and ultimately generate a CSV file that is then picked up by our label software and the end result is basically printing labels from excel. At least that is what the end user thinks.

After creating a new application to do the same thing but in a different department the code seams to have stopped working and I cannot figure out why.

What Happens is everything gets jammed into one line and it never indexes to the next row. Does anyone have any thoughts?

Below is the code. Thanks in advance.

Rich (BB code):
Private Sub q96print_Click()
'writes data to text file on local C:\ to generate label from Bartender Commander


Dim TextFile As Integer
Dim FilePath As String
Dim column_num As Integer
Dim record_num As Integer
Dim record_count As Integer
Dim package_qty As Integer
Dim Package_Sum As Integer


Package_Sum = Range("k72").Value
record_count = Range("x7").Value
package_count = Range("ag11").Value
lRow = 11


'write data to text file
FilePath = "C:\Bartender Commander Folder\q96export.csv"
TextFile = FreeFile
Open FilePath For Output As TextFile
Write #TextFile , "SO#", "PO#", "Customer", "# of packages", "po line", "ship date", "qty", "item", "description", "box info"
For record_num = 1 To record_count
    For package_qty = 1 To package_count
        For column_num = 1 To 9
            Write #TextFile , Range("ad11:al60").Cells(record_num, column_num).Value,
            If column_num = 9 Then
  
                Write #TextFile , package_qty & " of " & package_count,
         
            End If
       Next column_num
       Next package_qty
    package_count = Range("A" & (lRow + 1)).Value
    lRow = lRow + 1


Next record_num


Close TextFile






    package_count = Range("Ag11").Value
    lRow = 11


'''calls for the clear macro
'call q96clear_Click()


End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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