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?
 

antman2988

Board Regular
Joined
Jun 28, 2018
Messages
66
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.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,147,748
Messages
5,742,978
Members
423,769
Latest member
LongToast

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
Top