+ Reply to Thread
Results 1 to 4 of 4

Copy only columns that have certain values

  1. #1
    Registered User
    Join Date
    12-04-2013
    Location
    NZ
    MS-Off Ver
    11
    Posts
    2

    Copy only columns that have certain values

    Hi,

    I am completely new at this, but I have searched and attempted things for days and can't figure out how to get something to do all of the things I want. I have a worksheet with values that change weekly (sample, attached). The number of rows and columns may change as well. However, columns A, B, and C will always have date, name and location data and therefore must be preserved. Aside from the headers, the values in the columns from D onward will include only the numbers 0, 1, 2, or 3.

    I need to copy the columns to Sheet2 and then delete all of the columns from D onward that do not have a 2 or a 3 in them. In other words, I need to always keep columns A, B, and C, and also keep any column (and all of its data) if a 2 and/or 3 shows up anywhere in the column.

    I imagine there is even a quicker way to cherry pick the first three columns, as well as any other columns that have a 2 or 3 in them, and then paste them to the second worksheet. However, either approach will meet the need well enough.

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copy only columns that have certain values

    Try the attached.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    12-04-2013
    Location
    NZ
    MS-Off Ver
    11
    Posts
    2

    Re: Copy only columns that have certain values

    Wow, that is a fast acting tool. It works well, and I cannot thank you enough. I honestly wish I could decode it, so I could tweak it, but I only sort of understand all of the statements.

    In any case, when I run it, it is almost perfect - it has only a couple of issues for my needs.

    1. I can't figure out why, but the column headings are not carried over to Sheet2. They are there in the sample you sent back, but if I add new columns and headers to Sheet1, the new headers don't come over.

    2. Any columns that don't have a 2 and/or 3 in them are included as empty columns in Sheet2. I need to eliminate them altogether on Sheet2 as I'm going to use Sheet2 as the source for other worksheets, pivot tables, and some charts. I could use an example that I found online that will do something garish like total the values in a column and if it is less than 1, it will cut the whole column and move everything left, but it's not a very "elegant" solution and certainly would not match what you've got going!

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copy only columns that have certain values

    Amended code:
    Attached Files Attached Files

+ 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] Copy values across columns
    By tarki in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-18-2014, 05:52 PM
  2. copy columns values to row
    By albert28 in forum Excel General
    Replies: 1
    Last Post: 07-30-2013, 10:46 PM
  3. [SOLVED] Copy/Paste multiple columns as values based on another columns criteria
    By Dgp2012 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-28-2013, 06:50 AM
  4. Compare 2 columns and copy new values from the 2nd columns to a 3rd column
    By djarcadian in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-02-2013, 12:18 PM
  5. Copy columns values into separate columns
    By Mike_can in forum Excel General
    Replies: 7
    Last Post: 05-26-2006, 07:35 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