Extract/import to csv

crims0n

New Member
Joined
Aug 18, 2011
Messages
12
I have a code here that import data in an excel file to csv. It can import other laguages like japanese, chinese characters. It can also import numbers. My problem is, it cannot import the cell that contains only the number zero "0". Did i miss anything? Thanks

Code:
Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim FName As Variant
FName = Application
If FName <> False Then
Set SrcRg = ActiveSheet.UsedRange
End If
Set fst = CreateObject("ADODB.Stream")
fst.Type = 2
fst.Charset = "utf-8"
fst.Open
For Each CurrRow In SrcRg.Rows
CurrTextStr = ""
For Each CurrCell In CurrRow.Cells
If CurrCell.Value <> Empty Then
cellvalue = Replace(CurrCell.Value, Chr(34), Chr(34) & Chr(34))
CurrTextStr = CurrTextStr & """" & cellvalue & """" '& ""
Else
CurrTextStr = CurrTextStr '& ""
End If
Next
fst.writetext CurrTextStr, 1
If (fst.Position < fst.EOS) Then
fst.SetEOS = fst.Position
End If
Next
fst.SaveToFile "C:\Users\file.csv", 2
   MsgBox "Extract completed "
    End If
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi, :)

instead...
Code:
If CurrCell.Value <> Empty Then
...try this:
Code:
If Len(Trim(CurrCell.Value) > 0) Then
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,894
Members
452,948
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