Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 5th, 2016, 02:23 AM
Authorized User
 
Join Date: Apr 2009
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
Default Selective columns delete

I have an Oracle based report which has about 223 columns across the sheet. I just want to retain about 12 columns out of this report but doing this every time manually is a cumbersome activity.

The easiest way I could think of was to use activesheet.range($A$2,$B$2,$C$2,$D$2,$E$2,$F$2... .).entirecolumn.delete

However, since the range is quite big, I get a compile error every time I try to run this.

Any suggestions?

Regards
SMI
 
Old January 6th, 2016, 05:58 PM
Wrox Author
 
Join Date: Jan 2015
Posts: 35
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Which 12 of the columns do you want to keep?
  Spam!  
Old January 8th, 2016, 11:01 PM
Authorized User
 
Join Date: Oct 2015
Posts: 48
Thanks: 0
Thanked 5 Times in 5 Posts
Thumbs up Range of 200+columns

Hi,

Why export what you do not need, from Oracle,in the 1st place?

Have you tried Using a union function on them then Iterate over the new range?

Code:
CombinedRange2Delete = Union(UnwantedRange1,UnrantedRange2, ... ,UnwantedRange223)

For each(Current in CombinedRange2Delete)
  Current.Delete
Next.
Another approach: Since there is more Unwanted collumns then it is maybe better to 1st isolate the Wanted then Delete any, from total columns, that do not intersect with the wanted columns. Get the total columns then the columns you want then delete any Total columns not intersecting with the wanted columns.

Code:
WantedColumns = Union(WantedRange1, WantedRange2, ..., WantedRange10)
TotalColumns = Range(Column1Name:Column223Name)

For each(CurrentColumn in TotalColumns)
  IntersectColumns = Intersect(CurrentColumn , WantedColumns)
  if IntersectColumns is Nothing then
        CurrentColumn.Delete
  end if
Next.
If you wanna chat about it: [email protected]
__________________
Nostalgia 4 Infinity

Last edited by Zakalwe; January 8th, 2016 at 11:04 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to delete columns from a table aaronkoh Access VBA 0 March 27th, 2013 09:39 AM
Selective Display of information on a panel JohnInPomeroy BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 March 21st, 2010 05:07 AM
Problem with selective counting still_learning XSLT 1 March 22nd, 2007 06:27 PM
Moving Columns over on the fly with delete query kevorkian SQL Server ASP 0 March 17th, 2006 12:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.