+ Reply to Thread
Results 1 to 4 of 4

Search for 3 specific columns and copy

  1. #1
    Registered User
    Join Date
    06-28-2011
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    16

    Search for 3 specific columns and copy

    Hi everyone,

    I have a worksheet with lots of random rows and columns. I would like to use VBA to find 3 specific columns, copy those columns and paste them into a new sheet. What would the code look like?

    Ctrl+f doesn't seem to work very well because after highlighting my first column, i want to search for my next column but excel will run the search in the highlighted column.

    I tried using relative references, but again that wouldn't work because the second column I need might be 6 cells to the left on the first worksheet, but 2 cells to the right on the second worksheet. Any thoughts? Thanks in advance!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,532

    Re: Search for 3 specific columns and copy

    Post a sample workbook with some typical data indicating which columns to select and why and where you want them to be copied.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    06-28-2011
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Search for 3 specific columns and copy

    hi, here is the sample file. basically i would like to search for 3 specific column titles (doctor, discipline, recovery) in sheet 1 and paste the entire column (along with the column contents) in to sheet 2.
    Attached Files Attached Files

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,532

    Re: Search for 3 specific columns and copy

    OK, this works:

    Please Login or Register  to view this content.

    I am not overly happy with it, in that I have to select the sheets. That said, it seems to do what you have asked for.

    There's probably a neater way of finding the column numbers and it's not really scaleable ... but it would easily cope with, say, half a dozen columns.

    I'm guessing there's a better way by storing the columns in arrays but that's not my strength.

    Lastly, there's no error checking so, if a heading isn't there, the results will be unpredictable.


    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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