Copy data to textfile

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
I have the code that exports my data into a textfile as a CSV. The code works great except that if any cell has 0 (Zero), it shows as $-. Is there a way to export the 0's as an integer when creating the text file?

VBA Code:
Set BkUp = Workbooks.Add
Rng.Copy BkUp.Sheets(1).Range("A1")
With BkUp
    .Sheets(1).Columns("F:F").NumberFormat = "0.0000000000"
    .Sheets(1).Columns("K:K").NumberFormat = "0.0000000000"
   
    For Each c In Wks.Range("S7:S" & LRow)
        If Not c.Comment Is Nothing Then
            With BkUp.Sheets(1).Cells(c.Row - 6, "S")
                .Value = .Value & COMMENT_DELIMITER & c.Comment.Text
            End With
        End If
    Next c
   
    .SaveAs Filename:=txtFile, FileFormat:=xlCSV
    .Close False
End With
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
it shows as $-. Is there a way to export the 0's
I assume you have a format in the cell that shows $ - in the cell when the value is 0.
An option could be to replace that format with "General" format only if there is a 0 in the cell.

Try the following.
Replace the following format in the macro with the format you have in those cells.
"_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"

VBA Code:
  Set BkUp = Workbooks.Add
  Rng.Copy BkUp.Sheets(1).Range("A1")
  With BkUp
    .Sheets(1).Columns("F:F").NumberFormat = "0.0000000000"
    .Sheets(1).Columns("K:K").NumberFormat = "0.0000000000"
   
    For Each c In Wks.Range("S7:S" & LRow)
        If Not c.Comment Is Nothing Then
            With BkUp.Sheets(1).Cells(c.Row - 6, "S")
                .Value = .Value & COMMENT_DELIMITER & c.Comment.Text
            End With
        End If
    Next c
    
    Application.FindFormat.NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
    Application.ReplaceFormat.NumberFormat = "General"
    .Sheets(1).Cells.Replace What:="0", Replacement:="0", LookAt:=xlWhole, _
      SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
    Application.FindFormat.Clear
    Application.ReplaceFormat.Clear

    .SaveAs Filename:=txtFile, FileFormat:=xlCSV, local:=True
    .Close False
  End With
 
Upvote 0

Forum statistics

Threads
1,215,013
Messages
6,122,694
Members
449,092
Latest member
snoom82

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