My macro creates CSV files but they are carrying over all the blank cells as well so they're extremely heavy.

Jorge_Excel

New Member
Joined
Jul 10, 2013
Messages
6
How can I solve this problem? I tried recording a macro that finds all the blank cells (with F5) but that finds billions of cells.

My code for the CSV exporter is currently:

Sub NewCopyToCSV()
Dim MyPath As String
Dim MyFileName As String
'The path and file names:
MyPath = "C:\Users\catet7\Desktop\"


Sheets("Result").Select
MyFileName = Range("A2").Value & " CSV created on " & " " & Format(Date, "dd.mm.yy")


'Makes sure the path name ends with "\":
If Not Right(MyPath, 1) = "\" Then MyPath = MyPath & "\"
'Makes sure the filename ends with ".csv"
If Not Right(MyFileName, 4) = ".csv" Then MyFileName = MyFileName & ".csv"


'Copies the sheet to a new workbook:
Sheets("Result").Copy
'The new workbook becomes Activeworkbook:
With ActiveWorkbook
'Saves the new workbook to given folder / filename:
.SaveAs Filename:= _
MyPath & MyFileName, _
FileFormat:=xlCSV, _
CreateBackup:=False
'Closes the file
.Close False
End With
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I don't understand, because your code unchanged (other than the file path) works perfectly and creates a small .csv

I wonder if you have a cell containing something way deep in your sheet..

In the sheet Result, press Ctrl-End. Which cell does that move you to? If that is IV234567 or something it would mean that you could get loads of extra bagage. See what is causing it. Some formatting or so?

Easiest to get rid of it is to delete all columns to the right of your range of interest and all rows below. Make sure first that there are no columns or rows hidden.
 
Upvote 0
Just do it by hand! It should be a once off only. Do what i explained above. It could also reduce your file size considerably as a bonus
 
Upvote 0
Just like you guessed, when I pressed Ctrl End the cursor went all the way down to V1048576. Then I hit F5 to select all the blanks and delete and Excel is not responding anymore. God ****! Thanks man
 
Upvote 0
The alternative is to copy just your used range to a new sheet, format it and then delete the other sheet.

Although Excel is supposed to be able to handle it, there is usually an issue when you have stuff close to the bottom border and try to get rid of it...

good luck, keep smiling, in the end it 'll run better.
 
Upvote 0

Forum statistics

Threads
1,215,566
Messages
6,125,596
Members
449,238
Latest member
wcbyers

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