Save as CSV in VBA with blanks not zeroes [on hold]VBA macro which filters and splits dataset into new...

Isn't using the Extrusion Multiplier like cheating?

How does Arcane Armament interact with the Artillerist Artificer's Wand Prototype feature?

Can an insurance company drop you after receiving a bill and refusing to pay?

What is wrong with using bare except?

Cryptic with missing capitals

What is this metal M-shaped device for?

Why does lambda auto& parameter choose const overload?

Am I a Rude Number?

Typing Amharic inside a math equation?

What is the in-universe cost of a TIE fighter?

Magento 2 : Call Helper Without Using __construct in Own Module

How do I say "Brexit" in Latin?

Breaking a Loop in Tikz

Why is working on the same position for more than 15 years not a red flag?

If I sold a PS4 game I owned the disc for, can I reinstall it digitally?

How would one buy a used TIE Fighter or X-Wing?

Can a dragon be stuck looking like a human?

Does Windows 10's telemetry include sending *.doc files if Word crashed?

Is there a standard way to treat events with unknown times (missing time data)?

Every character has a name - does this lead to too many named characters?

How can animals be objects of ethics without being subjects as well?

Is there any differences between "Gucken" and "Schauen"?

What creature do these Alchemical Humonculus actions target?

What is a jet (unit) shown in Windows 10 calculator?



Save as CSV in VBA with blanks not zeroes [on hold]


VBA macro which filters and splits dataset into new workbooksFunction to return a string legal for a range nameInterpolating data of multiple trainsEliminating empty spreadsheet cells from a rangeMaking a report from payroll detailsExtract String From Text (Word)Lots of different operations on workbooks in ExcelGeneral function to test for empty/no-value controlsManaging Excel Application State /w Multiple SubroutinesFind winning move in Tic-Tac-Toe with boolean arrays in VBA













-3












$begingroup$


I wrote this VBA Macro to save a range of values into a CSV:



Sub exportRangeToCSVFile()

Set myWB = ThisWorkbook

myCSVFileName = myWB.Path & "" & "Format_CSV-" & VBA.Format(VBA.Now, "dd-MMM-yyyy hh-mm") & ".csv"

Range("B5:X260").Select

Selection.Copy
Workbooks.Add
ActiveSheet.Paste

ActiveWorkbook.SaveAs filename:=myCSVFileName, FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True

End Sub


However, the resulting CSV always replaces empty cells with "0" and not blanks. How can I save the CSV with blanks and NOT zeroes?










share|improve this question









New contributor




emcor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



put on hold as off-topic by πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, IEatBagels, 200_success, Mathieu Guindon 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, IEatBagels, 200_success, Mathieu Guindon

If this question can be reworded to fit the rules in the help center, please edit the question.
















  • $begingroup$
    Welcome to Code Review! Unfortunately this post is off-topic for this site. Please read What topics can I ask about here? - note that it states "If you are looking for feedback on a specific working piece of code...then you are in the right place!" Also, when posting your question, there should have been text on the side that read "Your question must contain code that is already working correctly..." When you have fixed the code, please edit your post to include the working code and it can be reviewed."
    $endgroup$
    – Sᴀᴍ Onᴇᴌᴀ
    2 days ago










  • $begingroup$
    @SᴀᴍOnᴇᴌᴀ It doesnt make sense to ask a question about something which already works.
    $endgroup$
    – emcor
    2 days ago






  • 5




    $begingroup$
    It seems you may have the wrong perception about this site. Did you look at that first link in my comment above? If that doesn't explain it, then maybe "Which Site?" and "Code Review or not?" will help...
    $endgroup$
    – Sᴀᴍ Onᴇᴌᴀ
    2 days ago










  • $begingroup$
    It doesnt make sense to ask a question about something which already works - wrong. it's not because it "works" that it's efficient, maintainable, reliable, or adhering to best practices. For example Range("B5:X260").Select followed by Selection.Copy, should be Range("B5:X260").Copy; the Workbook object reference returned by Workbooks.Add could be held by a local variable, which would allow properly qualifying the ActiveSheet.Paste call and remove the need to rely on ActiveSheet altogether. myWB doesn't look like it's declared; Option Explicit should be specified.
    $endgroup$
    – Mathieu Guindon
    2 days ago








  • 1




    $begingroup$
    Actually myWB is redundant, ThisWorkbook is perfectly unambiguous and will always refer to the workbook that contains the VBA code. Unqualified Range call is implicitly referring to whatever the ActiveSheet is, but the code clearly means to work against a very specific sheet. As for the zeroes, you need to understand that the numeric representation of an "empty cell" is a zero. If you need them to be empty strings (do you? not clear what "blanks" stands for), then they're not blanks anymore - we'd need to know what B5:X260 contains in order to change how it's represented in CSV.
    $endgroup$
    – Mathieu Guindon
    2 days ago
















-3












$begingroup$


I wrote this VBA Macro to save a range of values into a CSV:



Sub exportRangeToCSVFile()

Set myWB = ThisWorkbook

myCSVFileName = myWB.Path & "" & "Format_CSV-" & VBA.Format(VBA.Now, "dd-MMM-yyyy hh-mm") & ".csv"

Range("B5:X260").Select

Selection.Copy
Workbooks.Add
ActiveSheet.Paste

ActiveWorkbook.SaveAs filename:=myCSVFileName, FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True

End Sub


However, the resulting CSV always replaces empty cells with "0" and not blanks. How can I save the CSV with blanks and NOT zeroes?










share|improve this question









New contributor




emcor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



put on hold as off-topic by πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, IEatBagels, 200_success, Mathieu Guindon 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, IEatBagels, 200_success, Mathieu Guindon

If this question can be reworded to fit the rules in the help center, please edit the question.
















  • $begingroup$
    Welcome to Code Review! Unfortunately this post is off-topic for this site. Please read What topics can I ask about here? - note that it states "If you are looking for feedback on a specific working piece of code...then you are in the right place!" Also, when posting your question, there should have been text on the side that read "Your question must contain code that is already working correctly..." When you have fixed the code, please edit your post to include the working code and it can be reviewed."
    $endgroup$
    – Sᴀᴍ Onᴇᴌᴀ
    2 days ago










  • $begingroup$
    @SᴀᴍOnᴇᴌᴀ It doesnt make sense to ask a question about something which already works.
    $endgroup$
    – emcor
    2 days ago






  • 5




    $begingroup$
    It seems you may have the wrong perception about this site. Did you look at that first link in my comment above? If that doesn't explain it, then maybe "Which Site?" and "Code Review or not?" will help...
    $endgroup$
    – Sᴀᴍ Onᴇᴌᴀ
    2 days ago










  • $begingroup$
    It doesnt make sense to ask a question about something which already works - wrong. it's not because it "works" that it's efficient, maintainable, reliable, or adhering to best practices. For example Range("B5:X260").Select followed by Selection.Copy, should be Range("B5:X260").Copy; the Workbook object reference returned by Workbooks.Add could be held by a local variable, which would allow properly qualifying the ActiveSheet.Paste call and remove the need to rely on ActiveSheet altogether. myWB doesn't look like it's declared; Option Explicit should be specified.
    $endgroup$
    – Mathieu Guindon
    2 days ago








  • 1




    $begingroup$
    Actually myWB is redundant, ThisWorkbook is perfectly unambiguous and will always refer to the workbook that contains the VBA code. Unqualified Range call is implicitly referring to whatever the ActiveSheet is, but the code clearly means to work against a very specific sheet. As for the zeroes, you need to understand that the numeric representation of an "empty cell" is a zero. If you need them to be empty strings (do you? not clear what "blanks" stands for), then they're not blanks anymore - we'd need to know what B5:X260 contains in order to change how it's represented in CSV.
    $endgroup$
    – Mathieu Guindon
    2 days ago














-3












-3








-3





$begingroup$


I wrote this VBA Macro to save a range of values into a CSV:



Sub exportRangeToCSVFile()

Set myWB = ThisWorkbook

myCSVFileName = myWB.Path & "" & "Format_CSV-" & VBA.Format(VBA.Now, "dd-MMM-yyyy hh-mm") & ".csv"

Range("B5:X260").Select

Selection.Copy
Workbooks.Add
ActiveSheet.Paste

ActiveWorkbook.SaveAs filename:=myCSVFileName, FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True

End Sub


However, the resulting CSV always replaces empty cells with "0" and not blanks. How can I save the CSV with blanks and NOT zeroes?










share|improve this question









New contributor




emcor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




I wrote this VBA Macro to save a range of values into a CSV:



Sub exportRangeToCSVFile()

Set myWB = ThisWorkbook

myCSVFileName = myWB.Path & "" & "Format_CSV-" & VBA.Format(VBA.Now, "dd-MMM-yyyy hh-mm") & ".csv"

Range("B5:X260").Select

Selection.Copy
Workbooks.Add
ActiveSheet.Paste

ActiveWorkbook.SaveAs filename:=myCSVFileName, FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True

End Sub


However, the resulting CSV always replaces empty cells with "0" and not blanks. How can I save the CSV with blanks and NOT zeroes?







vba excel csv formatting






share|improve this question









New contributor




emcor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




emcor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Mathieu Guindon

60.8k14147419




60.8k14147419






New contributor




emcor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









emcoremcor

951




951




New contributor




emcor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





emcor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






emcor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, IEatBagels, 200_success, Mathieu Guindon 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, IEatBagels, 200_success, Mathieu Guindon

If this question can be reworded to fit the rules in the help center, please edit the question.







put on hold as off-topic by πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, IEatBagels, 200_success, Mathieu Guindon 2 days ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, IEatBagels, 200_success, Mathieu Guindon

If this question can be reworded to fit the rules in the help center, please edit the question.












  • $begingroup$
    Welcome to Code Review! Unfortunately this post is off-topic for this site. Please read What topics can I ask about here? - note that it states "If you are looking for feedback on a specific working piece of code...then you are in the right place!" Also, when posting your question, there should have been text on the side that read "Your question must contain code that is already working correctly..." When you have fixed the code, please edit your post to include the working code and it can be reviewed."
    $endgroup$
    – Sᴀᴍ Onᴇᴌᴀ
    2 days ago










  • $begingroup$
    @SᴀᴍOnᴇᴌᴀ It doesnt make sense to ask a question about something which already works.
    $endgroup$
    – emcor
    2 days ago






  • 5




    $begingroup$
    It seems you may have the wrong perception about this site. Did you look at that first link in my comment above? If that doesn't explain it, then maybe "Which Site?" and "Code Review or not?" will help...
    $endgroup$
    – Sᴀᴍ Onᴇᴌᴀ
    2 days ago










  • $begingroup$
    It doesnt make sense to ask a question about something which already works - wrong. it's not because it "works" that it's efficient, maintainable, reliable, or adhering to best practices. For example Range("B5:X260").Select followed by Selection.Copy, should be Range("B5:X260").Copy; the Workbook object reference returned by Workbooks.Add could be held by a local variable, which would allow properly qualifying the ActiveSheet.Paste call and remove the need to rely on ActiveSheet altogether. myWB doesn't look like it's declared; Option Explicit should be specified.
    $endgroup$
    – Mathieu Guindon
    2 days ago








  • 1




    $begingroup$
    Actually myWB is redundant, ThisWorkbook is perfectly unambiguous and will always refer to the workbook that contains the VBA code. Unqualified Range call is implicitly referring to whatever the ActiveSheet is, but the code clearly means to work against a very specific sheet. As for the zeroes, you need to understand that the numeric representation of an "empty cell" is a zero. If you need them to be empty strings (do you? not clear what "blanks" stands for), then they're not blanks anymore - we'd need to know what B5:X260 contains in order to change how it's represented in CSV.
    $endgroup$
    – Mathieu Guindon
    2 days ago


















  • $begingroup$
    Welcome to Code Review! Unfortunately this post is off-topic for this site. Please read What topics can I ask about here? - note that it states "If you are looking for feedback on a specific working piece of code...then you are in the right place!" Also, when posting your question, there should have been text on the side that read "Your question must contain code that is already working correctly..." When you have fixed the code, please edit your post to include the working code and it can be reviewed."
    $endgroup$
    – Sᴀᴍ Onᴇᴌᴀ
    2 days ago










  • $begingroup$
    @SᴀᴍOnᴇᴌᴀ It doesnt make sense to ask a question about something which already works.
    $endgroup$
    – emcor
    2 days ago






  • 5




    $begingroup$
    It seems you may have the wrong perception about this site. Did you look at that first link in my comment above? If that doesn't explain it, then maybe "Which Site?" and "Code Review or not?" will help...
    $endgroup$
    – Sᴀᴍ Onᴇᴌᴀ
    2 days ago










  • $begingroup$
    It doesnt make sense to ask a question about something which already works - wrong. it's not because it "works" that it's efficient, maintainable, reliable, or adhering to best practices. For example Range("B5:X260").Select followed by Selection.Copy, should be Range("B5:X260").Copy; the Workbook object reference returned by Workbooks.Add could be held by a local variable, which would allow properly qualifying the ActiveSheet.Paste call and remove the need to rely on ActiveSheet altogether. myWB doesn't look like it's declared; Option Explicit should be specified.
    $endgroup$
    – Mathieu Guindon
    2 days ago








  • 1




    $begingroup$
    Actually myWB is redundant, ThisWorkbook is perfectly unambiguous and will always refer to the workbook that contains the VBA code. Unqualified Range call is implicitly referring to whatever the ActiveSheet is, but the code clearly means to work against a very specific sheet. As for the zeroes, you need to understand that the numeric representation of an "empty cell" is a zero. If you need them to be empty strings (do you? not clear what "blanks" stands for), then they're not blanks anymore - we'd need to know what B5:X260 contains in order to change how it's represented in CSV.
    $endgroup$
    – Mathieu Guindon
    2 days ago
















$begingroup$
Welcome to Code Review! Unfortunately this post is off-topic for this site. Please read What topics can I ask about here? - note that it states "If you are looking for feedback on a specific working piece of code...then you are in the right place!" Also, when posting your question, there should have been text on the side that read "Your question must contain code that is already working correctly..." When you have fixed the code, please edit your post to include the working code and it can be reviewed."
$endgroup$
– Sᴀᴍ Onᴇᴌᴀ
2 days ago




$begingroup$
Welcome to Code Review! Unfortunately this post is off-topic for this site. Please read What topics can I ask about here? - note that it states "If you are looking for feedback on a specific working piece of code...then you are in the right place!" Also, when posting your question, there should have been text on the side that read "Your question must contain code that is already working correctly..." When you have fixed the code, please edit your post to include the working code and it can be reviewed."
$endgroup$
– Sᴀᴍ Onᴇᴌᴀ
2 days ago












$begingroup$
@SᴀᴍOnᴇᴌᴀ It doesnt make sense to ask a question about something which already works.
$endgroup$
– emcor
2 days ago




$begingroup$
@SᴀᴍOnᴇᴌᴀ It doesnt make sense to ask a question about something which already works.
$endgroup$
– emcor
2 days ago




5




5




$begingroup$
It seems you may have the wrong perception about this site. Did you look at that first link in my comment above? If that doesn't explain it, then maybe "Which Site?" and "Code Review or not?" will help...
$endgroup$
– Sᴀᴍ Onᴇᴌᴀ
2 days ago




$begingroup$
It seems you may have the wrong perception about this site. Did you look at that first link in my comment above? If that doesn't explain it, then maybe "Which Site?" and "Code Review or not?" will help...
$endgroup$
– Sᴀᴍ Onᴇᴌᴀ
2 days ago












$begingroup$
It doesnt make sense to ask a question about something which already works - wrong. it's not because it "works" that it's efficient, maintainable, reliable, or adhering to best practices. For example Range("B5:X260").Select followed by Selection.Copy, should be Range("B5:X260").Copy; the Workbook object reference returned by Workbooks.Add could be held by a local variable, which would allow properly qualifying the ActiveSheet.Paste call and remove the need to rely on ActiveSheet altogether. myWB doesn't look like it's declared; Option Explicit should be specified.
$endgroup$
– Mathieu Guindon
2 days ago






$begingroup$
It doesnt make sense to ask a question about something which already works - wrong. it's not because it "works" that it's efficient, maintainable, reliable, or adhering to best practices. For example Range("B5:X260").Select followed by Selection.Copy, should be Range("B5:X260").Copy; the Workbook object reference returned by Workbooks.Add could be held by a local variable, which would allow properly qualifying the ActiveSheet.Paste call and remove the need to rely on ActiveSheet altogether. myWB doesn't look like it's declared; Option Explicit should be specified.
$endgroup$
– Mathieu Guindon
2 days ago






1




1




$begingroup$
Actually myWB is redundant, ThisWorkbook is perfectly unambiguous and will always refer to the workbook that contains the VBA code. Unqualified Range call is implicitly referring to whatever the ActiveSheet is, but the code clearly means to work against a very specific sheet. As for the zeroes, you need to understand that the numeric representation of an "empty cell" is a zero. If you need them to be empty strings (do you? not clear what "blanks" stands for), then they're not blanks anymore - we'd need to know what B5:X260 contains in order to change how it's represented in CSV.
$endgroup$
– Mathieu Guindon
2 days ago




$begingroup$
Actually myWB is redundant, ThisWorkbook is perfectly unambiguous and will always refer to the workbook that contains the VBA code. Unqualified Range call is implicitly referring to whatever the ActiveSheet is, but the code clearly means to work against a very specific sheet. As for the zeroes, you need to understand that the numeric representation of an "empty cell" is a zero. If you need them to be empty strings (do you? not clear what "blanks" stands for), then they're not blanks anymore - we'd need to know what B5:X260 contains in order to change how it's represented in CSV.
$endgroup$
– Mathieu Guindon
2 days ago










0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...