+ Reply to Thread
Results 1 to 6 of 6

Delete columns not stored in Array

  1. #1
    Forum Contributor
    Join Date
    03-02-2014
    Location
    usa
    MS-Off Ver
    MS 365
    Posts
    593

    Delete columns not stored in Array

    Hello,

    I have a worksheet which contains hundreds of columns.
    I only need some of them so, I want to delete the ones I don't need.
    I have saved the column numbers I need, in an array called ArrayCol (For example: 5, 7, 10, 3, 15.......)

    I need a macro which would delete all the columns except those listed in ArrayCol.

    Could you please advise?

    Thanks

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Delete columns not stored in Array


    Hello,

    yes but as the attachment is missing …

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Delete columns not stored in Array

    Hi Plans,

    You need to set a For Next loop starting at the largest column number and use a "Step -1" to see if the column you are on is in your array. If it isn't you need to delete that column with a :=Shift xlToLeft.

    It would be easier if you supplied a sample workbook.

    I'd also use a Split(",","5,7,10,3,15) to get your column numbers into your array.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,150

    Re: Delete columns not stored in Array

    Quote Originally Posted by plans View Post
    ... a macro which would delete all the columns except those listed in ArrayCol ...
    ???
    Please Login or Register  to view this content.

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,984

    Re: Delete columns not stored in Array

    or use CHOOSECOLS in a simple formula??
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  6. #6
    Forum Contributor
    Join Date
    03-02-2014
    Location
    usa
    MS-Off Ver
    MS 365
    Posts
    593

    Re: Delete columns not stored in Array

    Thank you mjr veverka!
    It works for me.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] If I have an Array with cell addresses stored in it, can I use .Row ?
    By RecordMan in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-31-2022, 07:03 PM
  2. See what values have stored in my array
    By Vagelisr in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-12-2018, 12:52 PM
  3. [SOLVED] VBA to select all ranges stored in array at once
    By sintek in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-27-2017, 03:50 AM
  4. [SOLVED] Activate sheet stored in array
    By sintek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-17-2017, 08:38 AM
  5. [SOLVED] Delete all rows that don't contain specific value stored in a cell
    By BPSJACK in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 09-05-2014, 11:34 AM
  6. [SOLVED] Delete entire Columns based on different Headers (Array)
    By WITJ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-13-2013, 02:46 PM
  7. How to delete block of elements from stored VBA array string
    By nuttyengineer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-27-2013, 07:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1