exce selection to csv

majkkollersk

New Member
Joined
Oct 26, 2017
Messages
1
Hi everyone,

This is my first post so please do not remove my profile in case I did not follow all the posting rules.

I am using a VBA script that saves an excel selection as .csv file, my issue is that my code (at the end of this question) returns a .csv file which looks as follows:


0



but I need it to look like this:

0


Anyone any ideas? Your help is greatly appreciated !



Public Sub ExcelRowsToCSV()

Dim iPtr As Integer
Dim sFileName As String
Dim intFH As Integer
Dim aRange As Range
Dim iLastColumn As Integer
Dim oCell As Range
Dim iRec As Long

Set aRange = Application.InputBox("Select a range:-", , Selection.Address, , , , , Type:=8)
iLastColumn = aRange.Column + aRange.Columns.Count - 1


iPtr = InStrRev(ActiveWorkbook.<wbr>FullName, ".")
sFileName = Left(ActiveSheet.Name, iPtr - 1) & ".csv"
sFileName = Application.GetSaveAsFilename(<wbr>InitialFileName:=sFileName, FileFilter:="CSV (Semicolon delimited) (*.csv), *.csv")
If sFileName = "False" Then Exit Sub

Close
intFH = FreeFile()
Open sFileName For Output As intFH

iRec = 0
For Each oCell In aRange
If oCell.Column = iLastColumn Then
Print #intFH , oCell.Value
iRec = iRec + 1
Else
Print #intFH , oCell.Value, ";";
End If
Next oCell

Close intFH

MsgBox "Finished: " & CStr(iRec) & "records written to" _
& sFileName & Space(10), vbOKOnly + vbInformation

End Sub



[FONT=verdana, sans-serif]





[/FONT]
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
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