Problem when using PasteSpecial with SkipBlanks on filtered table

%3CLINGO-SUB%20id%3D%22lingo-sub-2225218%22%20slang%3D%22en-US%22%3EProblem%20when%20using%20PasteSpecial%20with%20SkipBlanks%20on%20filtered%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2225218%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20written%20a%20VBA%20script%20to%20produce%20a%20report%20from%20an%20Excel%20table.%20Basically%2C%20the%20VBA%20script%20filters%20the%20table%20based%20on%20user%20selected%20criteria.%20It%20then%20copies%20a%20range%20of%20cells%20(using%20%3CSTRONG%3ESpecialCells(xlCellTypeVisible).Copy%3C%2FSTRONG%3E%20to%20ensure%20only%20the%20filtered%20data%20is%20copied).%20I%20am%20trying%20to%20then%20paste%20this%20into%20a%20new%20location%20(using%26nbsp%3B%3CSTRONG%3EPasteSpecial%20(xlPasteValues)%2C%20SkipBlanks%3A%3DTrue%3C%2FSTRONG%3E%20so%20that%20if%20there%20are%20any%20blank%20cells%20in%20the%20copied%20data%2C%20they%20don't%20overwrite%20what's%20already%20there).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20Excel%20is%20taking%20no%20notice%20of%20the%20%22%3CSTRONG%3Eskipblanks%3C%2FSTRONG%3E%22%20command%2C%20or%20perhaps%20it's%20just%20not%20recognising%20the%20blank%20cells%20as%20blank%20cells%20as%20it%20just%20pastes%20everything%2C%20blank%20cells%20included.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20tried%20the%20exact%20same%20thing%20using%20data%20copied%20normally%20(eg%20%3CSTRONG%3Eselection.copy%3C%2FSTRONG%3E)%20from%20an%20unfiltered%20table%20and%20it%20works%20perfectly%2C%20so%20the%20problem%20seems%20to%20be%20related%20to%20the%20fact%20that%20it%20is%20copied%20from%20a%20filtered%20table.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHas%20anyone%20experienced%20this%20issue%20and%2C%20if%20so%2C%20is%20there%20a%20simple%20solution%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3EMike%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2225218%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2225412%22%20slang%3D%22en-US%22%3ERe%3A%20Problem%20when%20using%20PasteSpecial%20with%20SkipBlanks%20on%20filtered%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2225412%22%20slang%3D%22en-US%22%3EThanks%20mathetes%2C%3CBR%20%2F%3EUnfortunately%20the%20filter%20function%20is%20not%20adequate%20in%20this%20instance%20as%20my%20code%20is%20part%20of%20a%20much%20larger%20piece%20which%20automates%20the%20production%20of%20multiple%20reports%20(separate%20workbooks).%3C%2FLINGO-BODY%3E
New Contributor

I have written a VBA script to produce a report from an Excel table. Basically, the VBA script filters the table based on user selected criteria. It then copies a range of cells (using SpecialCells(xlCellTypeVisible).Copy to ensure only the filtered data is copied). I am trying to then paste this into a new location (using PasteSpecial (xlPasteValues), SkipBlanks:=True so that if there are any blank cells in the copied data, they don't overwrite what's already there).

 

However, Excel is taking no notice of the "skipblanks" command, or perhaps it's just not recognising the blank cells as blank cells as it just pastes everything, blank cells included.

 

I've tried the exact same thing using data copied normally (eg selection.copy) from an unfiltered table and it works perfectly, so the problem seems to be related to the fact that it is copied from a filtered table.

 

Has anyone experienced this issue and, if so, is there a simple solution?

 

Thanks

Mike

2 Replies

@Apollo11 

 

It sounds to me as if you're involving VBA when you don't need to. If you have the most recent version of Excel installed, there's now a function called FILTER that can itself filter a table according to user-entered criteria. The report could then be generated from that filtered table.

 

Here's a great video that explains the function. https://www.youtube.com/watch?v=9I9DtFOVPIg

 

Learn everything about our brand-new Dynamic Arrays and how you can use them to build advanced spreadsheets. Arrays (CSE) have long been present in Excel, bu...
Thanks mathetes,
Unfortunately the filter function is not adequate in this instance as my code is part of a much larger piece which automates the production of multiple reports (separate workbooks).