VBA to save rows as CSV without empty rows

Jorgi

Board Regular
Joined
Jul 7, 2021
Messages
52
Office Version
  1. 2019
Platform
  1. Windows
Hello may I ask you to help me with VBA. I would like to save data via macro as CSV but only if there is a data. Every 6 rows equal to one piece of data element but sometimes the 6 rows can be empty (apart from column A) because there is no data and the file will have to be saved without the 6 empty rows. Thank you very much for your help

Initial file
1634825593353.png

outcome from macro
1634825869136.png
 
Yes, notepad shows correct length of the number. Thank you again
Marc L is there any other way to save the CSV file in the same place where is the main file? I have tested it on a share point and getting an error while the file is trying to save but when I try to generate CSV and the file is on my desktop drive then there is no issues and the file is saved perfectly. I'm not sure what needs to be added to the macro. Thank you very much as always for your help.

1637088854220.png
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Remove the On Error codeline and try …​
 
Upvote 0
Remove the On Error codeline and try …​
Apologies for the confusion but I meant the previous code works with share points but this one below doesn't work if the main file is located on share point. It perfectly works if the file is located on my desktop drive. Thank you

Sub Demo1()
Dim F%, Rw As Range
F = FreeFile
Open ThisWorkbook.Path & "\Export.csv" For Output As #F
With Application
For Each Rw In ActiveSheet.UsedRange.Columns("B:AZ").Rows
If (Rw.Cells.Count - .CountBlank(Rw)) > 1 Then Print #F, Join(.Index(Rw.Value2, 1, 0), ",")
Next
End With
Close #F
End Sub
 
Upvote 0
Read post #34 then apply & try your 'working' code …​
 
Upvote 0
Read post #34 then apply & try your 'working' code …​
Marc L the code you are referring to is something entirely different. I would like your code (below) works on the share point. Please see the code below this one is not working on SP. It only works on desktop drive. In this code below there is no on error codeline. I'm not sure how to modify your code below I'm so sorry and thank you if you can help.

Sub Demo1()
Dim F%, Rw As Range
F = FreeFile
Open ThisWorkbook.Path & "\Export.csv" For Output As #F
With Application
For Each Rw In ActiveSheet.UsedRange.Columns("B:AZ").Rows
If (Rw.Cells.Count - .CountBlank(Rw)) > 1 Then Print #F, Join(.Index(Rw.Value2, 1, 0), ",")
Next
End With
Close #F
End Sub
 
Upvote 0
As you can not write you have a 'working' code just posting an not complete code and far above all starting with On Error !​
The reason why you must try first your 'working' code after removing this codeline …​
Then if it still works without so you must see with your IT why my procedure does not work under SP.​
As you can create the file on a local drive then copy it to SP …​
 
Upvote 0
Hi Marc L, How the VBA code will look like if we want to change it from CSV format to xlsx? Thank you
 
Upvote 0
Hi Marc L, How the VBA code will look like if we want to change it from CSV format to xlsx? Thank you
As his icon shows, Marc's account was banned so he is no longer active on this forrum.
You may be better off posting a new thread, so it appears as a new unanswered question.
 
Upvote 0

Forum statistics

Threads
1,214,891
Messages
6,122,101
Members
449,066
Latest member
Andyg666

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