Export to CSV - format

here

New Member
Joined
Jun 29, 2011
Messages
3
Hi All

I am using VBA to export certain columns from excel to a csv file. The below extract is what I have done to choose the columns:

Code:
Print #1, Sheets("Output").Cells(i, 6).Text & separator & Sheets("Output").Cells(i, 12).Text & separator

Column 12 contains a value eg 1,234.45 in the actual sheet - am I able to convert/round it to 1234 directly in the script to prevent the user from having to change it in excel?

Thanks in advance :)
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try

Code:
Print #1, Sheets("Output").Cells(i, 6).Text & separator & CInt(Sheets("Output").Cells(i, 12).Value) & separator
 
Upvote 0
Excellent works exactly how i wanted it to!
Although I've not yet found this situation - if I was to have a negative number (either shown as -xx or (xx)) is there something similar to turn it to an absolute value?
 
Upvote 0
Try this

Code:
Print #1, Sheets("Output").Cells(i, 6).Text & separator & Abs(CInt(Sheets("Output").Cells(i, 12).Value)) & separator
 
Upvote 0
Thanks again!!

and hopefully my last two formats ;)

I need to set a field to be 3decimal places (so fill with 0) and then another to be fixed as 10 (pad with 0) and 2 dp.

Is this one possible?!

:)
 
Upvote 0
Try like this

Format(Sheets("Output").Cells(i, 12).Value, "0.000")

and

Format(Sheets("Output").Cells(i, 12).Value, "0000000000.00")
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,874
Members
452,949
Latest member
Dupuhini

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