Deleting Blank Lines After PasteSpecial

___

New Member
Joined
Nov 16, 2004
Messages
14
Hi All,

I'm having trouble trying to delete blank rows before saving as .txt (please see red code snippet, doesn't work).

Any help much appreciated.

Rich (BB code):
Dim wbSource As Workbook
Dim wsSource As Worksheet
Dim wbDest As Workbook
Dim fName As String

Set wbSource = ActiveWorkbook
Set wsSource = ActiveSheet
Set wbDest = Workbooks.Add
    
wsSource.Range("IS10:IV3000").Copy

wbDest.Worksheets(1).Cells(1, 1).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False

wbDest.Worksheets(1).Range("A:A").Select
wbDest.Worksheets(1).Range("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

wbDest.SaveAs Filename:="C:\Upload\" & Format(Now, "dd-mm-yy hh-mm-ss") & " proforma" & ".txt", FileFormat:=xlText, _
        CreateBackup:=False
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
If it's this line that's causing the trouble:

wbDest.Worksheets(1).Range("A:A").Select

just delete it. You can only select a range on the active sheet, and there is no need to do any selecting to delete the blank rows.
 
Upvote 0
Hi Andrew, Thanks for your quick reply.

I've removed that line of code but it still doesn't save the file without blank lines. It saves the file fine, just with blank lines between the data. Any ideas?
 
Upvote 0
I would have thought you would get an error on this line:

wbDest.Worksheets(1).Range("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

if there were no blank cells in column A.
 
Upvote 0
I've tried changing the code to...
Code:
wbDest.Activate
wbDest.Worksheets(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete

with no luck.

It saves the file no problem but just seems to ignore the delete lines bit. Is the above code totally wrong?
 
Upvote 0
Your original syntax is correct. Unless you have On Error Resume Next somewhere above that line, there must be some blank cells whose rows are deleted, otherwise you would get an error (no cells found).
 
Upvote 0
Yes, I'm getting that error now. It appears that the four columns that have been pasted, A, B, C and D, when opening with note pad and selecting all with a mouse drag, although they appear blank A and B are highlighted blue as if they contain data but C and D seem blank, not highlighted. Any idea what causes this?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,649
Members
448,975
Latest member
sweeberry

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