Blank Lines in CSV

caass

New Member
Joined
Jul 29, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hey everyone!

I have a csv that I am trying to clean in excel using VBA. If I open the file in notepad, it contains thousands of blank lines after my data ends which shouldn't be there. I want to flag the data and possibly automate deleting these rows in excel (amongst other data cleaning issues).

When I open in excel, there is only 900 rows of actual data. The problem is when I go to write the VBA, any formula I use to count the total number of rows is giving me 900 so I cannot figure out how to detect these extra rows using code.

If I go in manually and select the last row and ctrl+shft+down arrow and then delete, it then deletes the rows and shows that change in notepad. Is this just a problem because it is a csv? Is this an impossible task to automate?
 
You can handle it yourself by simple opening the file and resaving it as csv.
Since just opening it in excel is removing the blank rows, when you resave it they won't be there.

We could write a macro to do it but the longest part of the process is just navigating to the folder and selecting the file.
If you have some parameters that would allow the macro to pick the right file or do all files in a folder, then you may save some time.

These are not solutions though. You really don't want excel in the middle of what should be an automated job ie Source database ----> Production system.
It really does need to be fixed at the source.
I agree. It seems like it would be a simple issue of fixing the export to CSV script for the database. He should definitely contact whoever is in charge of administrating the database.
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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