+ Reply to Thread
Results 1 to 7 of 7

macro needed to include particular columns out of so many columns in a sheet

  1. #1
    Forum Contributor
    Join Date
    04-09-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    176

    macro needed to include particular columns out of so many columns in a sheet

    Hi to all,
    I have file with so many columns and i want to keep only columns i want.
    Data
    gen red yellow green white blue
    1 aa gg tt cc bb
    2 aa gg tt cc bb
    3 aa gg tt cc bb
    4 aa gg tt cc bb
    5 aa gg tt cc bb

    expected
    gen red white
    1 aa cc
    2 aa cc
    3 aa cc
    4 aa cc
    5 aa cc

    for example here i want to keep only gen, red and white columns only out of columns what i have in my data. I have so many columns in my original data but here i given just small example. can any one help me how to proceed with macro or any other way because removing manually taking long time for me. Any help would be highly appreciated
    Thanks in advance
    Regards,
    Genetist
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: macro needed to include particular columns out of so many columns in a sheet

    Is this what you mean?

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    04-09-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: macro needed to include particular columns out of so many columns in a sheet

    Dear Jolivanes,

    Thank you very much for your reply and your code working fine,but here i have to repeat if statement for several times (800 times)
    is there anyway to include names of all my columns to delete in one shot instead of writing IF multiple times.
    Thanks lot
    regards,
    genetist

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: macro needed to include particular columns out of so many columns in a sheet

    One way would be to list all the Column names to delete in a helper sheet.

    Please Login or Register  to view this content.
    Here the list is in Sheets("Helper") Column A.

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: macro needed to include particular columns out of so many columns in a sheet

    Or you could copy the columns you want to keep into a temp sheet and clear the sheet you copied the columns from.
    You can then copy the saved columns back into the sheet and delete the temp sheet.
    I guess it all depends on how many columns you want to save and how many you want to delete.

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: macro needed to include particular columns out of so many columns in a sheet

    See if this works. Try on a copy of your workbook.
    Change the Sheet reference (here Sheet2) as required

    Please Login or Register  to view this content.
    Let us know if either John H Davis' code or this code works for you

  7. #7
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: macro needed to include particular columns out of so many columns in a sheet

    if you've only got a relatively few columns to keep (or delete), you can also try something on the following lines.
    If you've got lots to keep (or delete) then you can input the ones to keep/delete in a file, helper sheet, or other, rather than through an array.
    Please Login or Register  to view this content.

+ 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. Macro to Compare two columns and publish sheet name in case columns dont match
    By adaws in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-06-2014, 01:21 PM
  2. [SOLVED] macro needed to extract specific columns out of multiple columns with their row data
    By genetist in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-07-2014, 12:49 AM
  3. [SOLVED] Sumif issue how to include two columns in a different sheet.
    By markDuffy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-04-2013, 11:34 AM
  4. Macro to include addtional rows/columns
    By namz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-10-2008, 11:47 PM
  5. [SOLVED] Excel macro to specify rows and columns to include in printouts
    By Generic Usenet Account in forum Excel General
    Replies: 2
    Last Post: 04-19-2005, 12: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